|
 |
asp_databases thread: Updating records
Message #1 by fred.sonderman@o... on Fri, 29 Mar 2002 09:13:38
|
|
Hi all,
I am having problems getting the following script to save for me. I hope
somebody will notice something out of place.
Thanks in advance,
Bill
<%@ LANGUAGE="VBSCRIPT" %>
<%
'Set how many records per page we want
InitialNumPerPage = 1
'Retrieve what page we're currently on
if request.form ("NumPerPageText")= "" AND request.querystring
("NumPerPage") = "" Then
NumPerPage = InitialNumPerPage
else
if request.form ("NumPerPageText") = "" Then
NumPerPage = request.querystring("NumPerPage")
Else
NumPerPage = request.form ("NumPerPageText")
End If
End If
Dim CurPage
if request.querystring("CurPage") = "" Then
CurPage = 1
else
CurPage = request.querystring("CurPage")
end if
'--Declare variable
Dim Dataconnection, cmdDC, RecordSet
Dim RecordToEdit, Updated
Set dataconnection = Server.CreateObject("ADODB.Connection")
dataconnection.Open "Provider=SQLOLEDB; DATA Source=default; initial
catalog=pubs; user ID=sa; Password=;"
set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection
'Open our recordset
Dim SQL
SQL = "SELECT * FROM stores"
cmdDC.CommandText = SQL
'Explicitly Create a recordset object
Dim rs
Set RecordSet = Server.CreateObject("ADODB.Recordset")
'*************************Paging system *******************************
'Set cursor location property
RecordSet.cursortype =3
RecordSet.cursorlocation =3
set RecordSet.ActiveConnection = Dataconnection
'Set the cache size = to the # of records/page
RecordSet.cacheSize = NumPerPage
'*************************End Paging system *******************************
RecordSet.Open cmdDC, , 0, 3
RecordSet.MoveFirst
RecordSet.PageSize = NumPerPage
'Get the max number of pages
Dim TotalPages
TotalPages = RecordSet.PageCount
'Set the absolute page
RecordSet.AbsolutePage = CurPage
'Counting variable for our recordset
Dim count,strSearch
'******** End Paging System
'************* Updating Record ***************
if Request.form("btnUpdate") = "SAVE" Then
'gather form field values
stor_name = request.form("stor_name")
city = request.form("city")
'define the update query
strUpdate = "UPDATE stores set stor_name='"&stor_name&"',
city='"&city&"' WHERE stor_id="&id&""
'execute the update
cmdDC.Execute(strUpdate)
updated = "True"
End if
'**********************************************
%>
<HTML>
<head>
<title>Stores information</title>
<script language="javascript">
<!--
//
function confirmsave()
{
var agree=confirm("Are you sure you want to make changes to this
record?");
if (agree)
return true;
else
return false;
}
// -->
</script>
</head>
<BODY>
<form name="storeForm" action="default.asp" method="post">
<table>
<tr>
<td>
<%
''First/Last butons
Response.write("<input type=button value=FIRST
onclick=""document.location.href='default.asp?Curpage=1&NumPerPage=")
response.write( NumPerPage & "';"">")
%>
</td>
<td>
<%
''Prev buton
If CurPage > 1 then
Response.write("<input type=button value=PREV
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage -1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''NEXT buton
If CInt(curpage) <> Cint(totalpages) then
Response.write("<input type=button value=NEXT
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage + 1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''LAST buton
Response.write("<input type=button value=LAST
onclick=""document.location.href='default.asp?Curpage=")
response.write( RecordSet.Pagecount
& "&NumPerPage=" & NumPerPage & "'"">")
%>
</td>
<td>
<input type="submit" method="post" value="SAVE"
name="btnUpdate" onClick="Return confirmsave()" title="Save this item">
</td>
<td>
<input type="submit" value="Search By Store
Number" name="FindButton">
</td>
<td>
<select size=1 name="FindIDText" >
<%
Dim sql2,Prod
Set Prod = server.createObject
("ADODB.Recordset")
sql2 = "SELECT * FROM stores Order By
stor_id desc"
prod.Open sql2,DataConnection
Do While Not Prod.EOF
response.write "<option>" & Prod
("stor_id") & "</option>"
prod.MoveNext
loop
%>
</select>
</td>
</table>
<% IF Updated = "True" Then %>
<b><%= RecordSet.Fields("stor_id") %></b>
<p> has been updated.</p>
<%End if %>
<%
'Set count to equal to zero
count = 0
Do while Not RecordSet.EOF and Count < RecordSet.PageSize
%>
<table>
<tr>
<td>
Store ID:
</td>
<td>
<input name="ID" type="hidden" value="<%=
RecordSet.fields("stor_id")%>"><%= RecordSet.fields("stor_id") %>
</td>
</tr>
<tr>
<td colspan="4">
<hr>
</td>
</tr>
<tr>
<td>
Store Name:
</td>
<td>
<input type="text" name="stor_name" value="<%=
RecordSet.fields("stor_name")%>">
</td>
<td>
Store Location:
</td>
<td>
<input type="text" name="city" value="<%=
RecordSet.fields("city")%>">
</td>
</tr>
<%
count = count +1
RecordSet.movenext
loop
%>
</table>
</form>
</BODY>
</HTML>
<%
RecordSet.close
set RecordSet = Nothing
set cmdDC = Nothing
DataConnection.Close
SEt DataConnection = Nothing
%>
Message #2 by "Kim Iwan Hansen" <kimiwan@k...> on Sat, 30 Mar 2002 01:19:05 +0100
|
|
But you figured out what the problem was now? :o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 17:07
To: ASP Databases
Subject: [asp_databases] RE: Updating records
Hi Kim,
I am not getting a message, and it is responding like it did do the
update. Oh, but no changes are being made. I I included all the code
because I am connecting up to the pubs database, and I thought it would be
helpful.
Thanks for taking the time to respond.
> - Got an error code?
- If you got one, did you look it up at google or microsoft's sites?
- Did you response.write the sql string out? (if so, try and post it)
- Etc.
Providing that kind of info will do more good than a couple hundred lines
of
wrapped asp code ;o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 09:14
To: ASP Databases
Subject: [asp_databases] Updating records
Hi all,
I am having problems getting the following script to save for me. I hope
somebody will notice something out of place.
Thanks in advance,
Bill
<%@ LANGUAGE="VBSCRIPT" %>
<%
'Set how many records per page we want
InitialNumPerPage = 1
'Retrieve what page we're currently on
if request.form ("NumPerPageText")= "" AND request.querystring
("NumPerPage") = "" Then
NumPerPage = InitialNumPerPage
else
if request.form ("NumPerPageText") = "" Then
NumPerPage = request.querystring("NumPerPage")
Else
NumPerPage = request.form ("NumPerPageText")
End If
End If
Dim CurPage
if request.querystring("CurPage") = "" Then
CurPage = 1
else
CurPage = request.querystring("CurPage")
end if
'--Declare variable
Dim Dataconnection, cmdDC, RecordSet
Dim RecordToEdit, Updated
Set dataconnection = Server.CreateObject("ADODB.Connection")
dataconnection.Open "Provider=SQLOLEDB; DATA Source=default; initial
catalog=pubs; user ID=sa; Password=;"
set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection
'Open our recordset
Dim SQL
SQL = "SELECT * FROM stores"
cmdDC.CommandText = SQL
'Explicitly Create a recordset object
Dim rs
Set RecordSet = Server.CreateObject("ADODB.Recordset")
'*************************Paging system *******************************
'Set cursor location property
RecordSet.cursortype =3
RecordSet.cursorlocation =3
set RecordSet.ActiveConnection = Dataconnection
'Set the cache size = to the # of records/page
RecordSet.cacheSize = NumPerPage
'*************************End Paging system *******************************
RecordSet.Open cmdDC, , 0, 3
RecordSet.MoveFirst
RecordSet.PageSize = NumPerPage
'Get the max number of pages
Dim TotalPages
TotalPages = RecordSet.PageCount
'Set the absolute page
RecordSet.AbsolutePage = CurPage
'Counting variable for our recordset
Dim count,strSearch
'******** End Paging System
'************* Updating Record ***************
if Request.form("btnUpdate") = "SAVE" Then
'gather form field values
stor_name = request.form("stor_name")
city = request.form("city")
'define the update query
strUpdate = "UPDATE stores set stor_name='"&stor_name&"',
city='"&city&"' WHERE stor_id="&id&""
'execute the update
cmdDC.Execute(strUpdate)
updated = "True"
End if
'**********************************************
%>
<HTML>
<head>
<title>Stores information</title>
<script language="javascript">
<!--
//
function confirmsave()
{
var agree=confirm("Are you sure you want to make changes to this
record?");
if (agree)
return true;
else
return false;
}
// -->
</script>
</head>
<BODY>
<form name="storeForm" action="default.asp" method="post">
<table>
<tr>
<td>
<%
''First/Last butons
Response.write("<input type=button value=FIRST
onclick=""document.location.href='default.asp?Curpage=1&NumPerPage=")
response.write( NumPerPage & "';"">")
%>
</td>
<td>
<%
''Prev buton
If CurPage > 1 then
Response.write("<input type=button value=PREV
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage -1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''NEXT buton
If CInt(curpage) <> Cint(totalpages) then
Response.write("<input type=button value=NEXT
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage + 1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''LAST buton
Response.write("<input type=button value=LAST
onclick=""document.location.href='default.asp?Curpage=")
response.write( RecordSet.Pagecount
& "&NumPerPage=" & NumPerPage & "'"">")
%>
</td>
<td>
<input type="submit" method="post" value="SAVE"
name="btnUpdate" onClick="Return confirmsave()" title="Save this item">
</td>
<td>
<input type="submit" value="Search By Store
Number" name="FindButton">
</td>
<td>
<select size=1 name="FindIDText" >
<%
Dim sql2,Prod
Set Prod = server.createObject
("ADODB.Recordset")
sql2 = "SELECT * FROM stores Order By
stor_id desc"
prod.Open sql2,DataConnection
Do While Not Prod.EOF
response.write "<option>" & Prod
("stor_id") & "</option>"
prod.MoveNext
loop
%>
</select>
</td>
</table>
<% IF Updated = "True" Then %>
<b><%= RecordSet.Fields("stor_id") %></b>
<p> has been updated.</p>
<%End if %>
<%
'Set count to equal to zero
count = 0
Do while Not RecordSet.EOF and Count < RecordSet.PageSize
%>
<table>
<tr>
<td>
Store ID:
</td>
<td>
<input name="ID" type="hidden" value="<%
RecordSet.fields("stor_id")%>"><%= RecordSet.fields("stor_id") %>
</td>
</tr>
<tr>
<td colspan="4">
<hr>
</td>
</tr>
<tr>
<td>
Store Name:
</td>
<td>
<input type="text" name="stor_name" value="<%
RecordSet.fields("stor_name")%>">
</td>
<td>
Store Location:
</td>
<td>
<input type="text" name="city" value="<%
RecordSet.fields("city")%>">
</td>
</tr>
<%
count = count +1
RecordSet.movenext
loop
%>
</table>
</form>
</BODY>
</HTML>
<%
RecordSet.close
set RecordSet = Nothing
set cmdDC = Nothing
DataConnection.Close
SEt DataConnection = Nothing
%>
Message #3 by "Kim Iwan Hansen" <kimiwan@k...> on Fri, 29 Mar 2002 14:46:59 +0100
|
|
- Got an error code?
- If you got one, did you look it up at google or microsoft's sites?
- Did you response.write the sql string out? (if so, try and post it)
- Etc.
Providing that kind of info will do more good than a couple hundred lines of
wrapped asp code ;o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 09:14
To: ASP Databases
Subject: [asp_databases] Updating records
Hi all,
I am having problems getting the following script to save for me. I hope
somebody will notice something out of place.
Thanks in advance,
Bill
<%@ LANGUAGE="VBSCRIPT" %>
<%
'Set how many records per page we want
InitialNumPerPage = 1
'Retrieve what page we're currently on
if request.form ("NumPerPageText")= "" AND request.querystring
("NumPerPage") = "" Then
NumPerPage = InitialNumPerPage
else
if request.form ("NumPerPageText") = "" Then
NumPerPage = request.querystring("NumPerPage")
Else
NumPerPage = request.form ("NumPerPageText")
End If
End If
Dim CurPage
if request.querystring("CurPage") = "" Then
CurPage = 1
else
CurPage = request.querystring("CurPage")
end if
'--Declare variable
Dim Dataconnection, cmdDC, RecordSet
Dim RecordToEdit, Updated
Set dataconnection = Server.CreateObject("ADODB.Connection")
dataconnection.Open "Provider=SQLOLEDB; DATA Source=default; initial
catalog=pubs; user ID=sa; Password=;"
set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection
'Open our recordset
Dim SQL
SQL = "SELECT * FROM stores"
cmdDC.CommandText = SQL
'Explicitly Create a recordset object
Dim rs
Set RecordSet = Server.CreateObject("ADODB.Recordset")
'*************************Paging system *******************************
'Set cursor location property
RecordSet.cursortype =3
RecordSet.cursorlocation =3
set RecordSet.ActiveConnection = Dataconnection
'Set the cache size = to the # of records/page
RecordSet.cacheSize = NumPerPage
'*************************End Paging system *******************************
RecordSet.Open cmdDC, , 0, 3
RecordSet.MoveFirst
RecordSet.PageSize = NumPerPage
'Get the max number of pages
Dim TotalPages
TotalPages = RecordSet.PageCount
'Set the absolute page
RecordSet.AbsolutePage = CurPage
'Counting variable for our recordset
Dim count,strSearch
'******** End Paging System
'************* Updating Record ***************
if Request.form("btnUpdate") = "SAVE" Then
'gather form field values
stor_name = request.form("stor_name")
city = request.form("city")
'define the update query
strUpdate = "UPDATE stores set stor_name='"&stor_name&"',
city='"&city&"' WHERE stor_id="&id&""
'execute the update
cmdDC.Execute(strUpdate)
updated = "True"
End if
'**********************************************
%>
<HTML>
<head>
<title>Stores information</title>
<script language="javascript">
<!--
//
function confirmsave()
{
var agree=confirm("Are you sure you want to make changes to this
record?");
if (agree)
return true;
else
return false;
}
// -->
</script>
</head>
<BODY>
<form name="storeForm" action="default.asp" method="post">
<table>
<tr>
<td>
<%
''First/Last butons
Response.write("<input type=button value=FIRST
onclick=""document.location.href='default.asp?Curpage=1&NumPerPage=")
response.write( NumPerPage & "';"">")
%>
</td>
<td>
<%
''Prev buton
If CurPage > 1 then
Response.write("<input type=button value=PREV
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage -1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''NEXT buton
If CInt(curpage) <> Cint(totalpages) then
Response.write("<input type=button value=NEXT
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage + 1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''LAST buton
Response.write("<input type=button value=LAST
onclick=""document.location.href='default.asp?Curpage=")
response.write( RecordSet.Pagecount
& "&NumPerPage=" & NumPerPage & "'"">")
%>
</td>
<td>
<input type="submit" method="post" value="SAVE"
name="btnUpdate" onClick="Return confirmsave()" title="Save this item">
</td>
<td>
<input type="submit" value="Search By Store
Number" name="FindButton">
</td>
<td>
<select size=1 name="FindIDText" >
<%
Dim sql2,Prod
Set Prod = server.createObject
("ADODB.Recordset")
sql2 = "SELECT * FROM stores Order By
stor_id desc"
prod.Open sql2,DataConnection
Do While Not Prod.EOF
response.write "<option>" & Prod
("stor_id") & "</option>"
prod.MoveNext
loop
%>
</select>
</td>
</table>
<% IF Updated = "True" Then %>
<b><%= RecordSet.Fields("stor_id") %></b>
<p> has been updated.</p>
<%End if %>
<%
'Set count to equal to zero
count = 0
Do while Not RecordSet.EOF and Count < RecordSet.PageSize
%>
<table>
<tr>
<td>
Store ID:
</td>
<td>
<input name="ID" type="hidden" value="<%
RecordSet.fields("stor_id")%>"><%= RecordSet.fields("stor_id") %>
</td>
</tr>
<tr>
<td colspan="4">
<hr>
</td>
</tr>
<tr>
<td>
Store Name:
</td>
<td>
<input type="text" name="stor_name" value="<%
RecordSet.fields("stor_name")%>">
</td>
<td>
Store Location:
</td>
<td>
<input type="text" name="city" value="<%
RecordSet.fields("city")%>">
</td>
</tr>
<%
count = count +1
RecordSet.movenext
loop
%>
</table>
</form>
</BODY>
</HTML>
<%
RecordSet.close
set RecordSet = Nothing
set cmdDC = Nothing
DataConnection.Close
SEt DataConnection = Nothing
%>
Message #4 by fred.sonderman@o... on Fri, 29 Mar 2002 17:06:52
|
|
Hi Kim,
I am not getting a message, and it is responding like it did do the
update. Oh, but no changes are being made. I I included all the code
because I am connecting up to the pubs database, and I thought it would be
helpful.
Thanks for taking the time to respond.
> - Got an error code?
- If you got one, did you look it up at google or microsoft's sites?
- Did you response.write the sql string out? (if so, try and post it)
- Etc.
Providing that kind of info will do more good than a couple hundred lines
of
wrapped asp code ;o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 09:14
To: ASP Databases
Subject: [asp_databases] Updating records
Hi all,
I am having problems getting the following script to save for me. I hope
somebody will notice something out of place.
Thanks in advance,
Bill
<%@ LANGUAGE="VBSCRIPT" %>
<%
'Set how many records per page we want
InitialNumPerPage = 1
'Retrieve what page we're currently on
if request.form ("NumPerPageText")= "" AND request.querystring
("NumPerPage") = "" Then
NumPerPage = InitialNumPerPage
else
if request.form ("NumPerPageText") = "" Then
NumPerPage = request.querystring("NumPerPage")
Else
NumPerPage = request.form ("NumPerPageText")
End If
End If
Dim CurPage
if request.querystring("CurPage") = "" Then
CurPage = 1
else
CurPage = request.querystring("CurPage")
end if
'--Declare variable
Dim Dataconnection, cmdDC, RecordSet
Dim RecordToEdit, Updated
Set dataconnection = Server.CreateObject("ADODB.Connection")
dataconnection.Open "Provider=SQLOLEDB; DATA Source=default; initial
catalog=pubs; user ID=sa; Password=;"
set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection
'Open our recordset
Dim SQL
SQL = "SELECT * FROM stores"
cmdDC.CommandText = SQL
'Explicitly Create a recordset object
Dim rs
Set RecordSet = Server.CreateObject("ADODB.Recordset")
'*************************Paging system *******************************
'Set cursor location property
RecordSet.cursortype =3
RecordSet.cursorlocation =3
set RecordSet.ActiveConnection = Dataconnection
'Set the cache size = to the # of records/page
RecordSet.cacheSize = NumPerPage
'*************************End Paging system *******************************
RecordSet.Open cmdDC, , 0, 3
RecordSet.MoveFirst
RecordSet.PageSize = NumPerPage
'Get the max number of pages
Dim TotalPages
TotalPages = RecordSet.PageCount
'Set the absolute page
RecordSet.AbsolutePage = CurPage
'Counting variable for our recordset
Dim count,strSearch
'******** End Paging System
'************* Updating Record ***************
if Request.form("btnUpdate") = "SAVE" Then
'gather form field values
stor_name = request.form("stor_name")
city = request.form("city")
'define the update query
strUpdate = "UPDATE stores set stor_name='"&stor_name&"',
city='"&city&"' WHERE stor_id="&id&""
'execute the update
cmdDC.Execute(strUpdate)
updated = "True"
End if
'**********************************************
%>
<HTML>
<head>
<title>Stores information</title>
<script language="javascript">
<!--
//
function confirmsave()
{
var agree=confirm("Are you sure you want to make changes to this
record?");
if (agree)
return true;
else
return false;
}
// -->
</script>
</head>
<BODY>
<form name="storeForm" action="default.asp" method="post">
<table>
<tr>
<td>
<%
''First/Last butons
Response.write("<input type=button value=FIRST
onclick=""document.location.href='default.asp?Curpage=1&NumPerPage=")
response.write( NumPerPage & "';"">")
%>
</td>
<td>
<%
''Prev buton
If CurPage > 1 then
Response.write("<input type=button value=PREV
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage -1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''NEXT buton
If CInt(curpage) <> Cint(totalpages) then
Response.write("<input type=button value=NEXT
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage + 1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''LAST buton
Response.write("<input type=button value=LAST
onclick=""document.location.href='default.asp?Curpage=")
response.write( RecordSet.Pagecount
& "&NumPerPage=" & NumPerPage & "'"">")
%>
</td>
<td>
<input type="submit" method="post" value="SAVE"
name="btnUpdate" onClick="Return confirmsave()" title="Save this item">
</td>
<td>
<input type="submit" value="Search By Store
Number" name="FindButton">
</td>
<td>
<select size=1 name="FindIDText" >
<%
Dim sql2,Prod
Set Prod = server.createObject
("ADODB.Recordset")
sql2 = "SELECT * FROM stores Order By
stor_id desc"
prod.Open sql2,DataConnection
Do While Not Prod.EOF
response.write "<option>" & Prod
("stor_id") & "</option>"
prod.MoveNext
loop
%>
</select>
</td>
</table>
<% IF Updated = "True" Then %>
<b><%= RecordSet.Fields("stor_id") %></b>
<p> has been updated.</p>
<%End if %>
<%
'Set count to equal to zero
count = 0
Do while Not RecordSet.EOF and Count < RecordSet.PageSize
%>
<table>
<tr>
<td>
Store ID:
</td>
<td>
<input name="ID" type="hidden" value="<%
RecordSet.fields("stor_id")%>"><%= RecordSet.fields("stor_id") %>
</td>
</tr>
<tr>
<td colspan="4">
<hr>
</td>
</tr>
<tr>
<td>
Store Name:
</td>
<td>
<input type="text" name="stor_name" value="<%
RecordSet.fields("stor_name")%>">
</td>
<td>
Store Location:
</td>
<td>
<input type="text" name="city" value="<%
RecordSet.fields("city")%>">
</td>
</tr>
<%
count = count +1
RecordSet.movenext
loop
%>
</table>
</form>
</BODY>
</HTML>
<%
RecordSet.close
set RecordSet = Nothing
set cmdDC = Nothing
DataConnection.Close
SEt DataConnection = Nothing
%>
Message #5 by Sonderman Fred W Contr OD4/DM <Fred.Sonderman@O...> on Sat, 30 Mar 2002 01:39:41 -0000
|
|
NO!!
-----Original Message-----
From: Kim Iwan Hansen [mailto:kimiwan@k...]
Sent: Friday, March 29, 2002 4:19 PM
To: ASP Databases
Subject: [asp_databases] RE: Updating records
But you figured out what the problem was now? :o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 17:07
To: ASP Databases
Subject: [asp_databases] RE: Updating records
Hi Kim,
I am not getting a message, and it is responding like it did do the
update. Oh, but no changes are being made. I I included all the code
because I am connecting up to the pubs database, and I thought it would be
helpful.
Thanks for taking the time to respond.
> - Got an error code?
- If you got one, did you look it up at google or microsoft's sites?
- Did you response.write the sql string out? (if so, try and post it)
- Etc.
Providing that kind of info will do more good than a couple hundred lines
of
wrapped asp code ;o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 09:14
To: ASP Databases
Subject: [asp_databases] Updating records
Hi all,
I am having problems getting the following script to save for me. I hope
somebody will notice something out of place.
Thanks in advance,
Bill
<%@ LANGUAGE="VBSCRIPT" %>
<%
'Set how many records per page we want
InitialNumPerPage = 1
'Retrieve what page we're currently on
if request.form ("NumPerPageText")= "" AND request.querystring
("NumPerPage") = "" Then
NumPerPage = InitialNumPerPage
else
if request.form ("NumPerPageText") = "" Then
NumPerPage = request.querystring("NumPerPage")
Else
NumPerPage = request.form ("NumPerPageText")
End If
End If
Dim CurPage
if request.querystring("CurPage") = "" Then
CurPage = 1
else
CurPage = request.querystring("CurPage")
end if
'--Declare variable
Dim Dataconnection, cmdDC, RecordSet
Dim RecordToEdit, Updated
Set dataconnection = Server.CreateObject("ADODB.Connection")
dataconnection.Open "Provider=SQLOLEDB; DATA Source=default; initial
catalog=pubs; user ID=sa; Password=;"
set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection
'Open our recordset
Dim SQL
SQL = "SELECT * FROM stores"
cmdDC.CommandText = SQL
'Explicitly Create a recordset object
Dim rs
Set RecordSet = Server.CreateObject("ADODB.Recordset")
'*************************Paging system *******************************
'Set cursor location property
RecordSet.cursortype =3
RecordSet.cursorlocation =3
set RecordSet.ActiveConnection = Dataconnection
'Set the cache size = to the # of records/page
RecordSet.cacheSize = NumPerPage
'*************************End Paging system *******************************
RecordSet.Open cmdDC, , 0, 3
RecordSet.MoveFirst
RecordSet.PageSize = NumPerPage
'Get the max number of pages
Dim TotalPages
TotalPages = RecordSet.PageCount
'Set the absolute page
RecordSet.AbsolutePage = CurPage
'Counting variable for our recordset
Dim count,strSearch
'******** End Paging System
'************* Updating Record ***************
if Request.form("btnUpdate") = "SAVE" Then
'gather form field values
stor_name = request.form("stor_name")
city = request.form("city")
'define the update query
strUpdate = "UPDATE stores set stor_name='"&stor_name&"',
city='"&city&"' WHERE stor_id="&id&""
'execute the update
cmdDC.Execute(strUpdate)
updated = "True"
End if
'**********************************************
%>
<HTML>
<head>
<title>Stores information</title>
<script language="javascript">
<!--
//
function confirmsave()
{
var agree=confirm("Are you sure you want to make changes to this
record?");
if (agree)
return true;
else
return false;
}
// -->
</script>
</head>
<BODY>
<form name="storeForm" action="default.asp" method="post">
<table>
<tr>
<td>
<%
''First/Last butons
Response.write("<input type=button value=FIRST
onclick=""document.location.href='default.asp?Curpage=1&NumPerPage=")
response.write( NumPerPage & "';"">")
%>
</td>
<td>
<%
''Prev buton
If CurPage > 1 then
Response.write("<input type=button value=PREV
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage -1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''NEXT buton
If CInt(curpage) <> Cint(totalpages) then
Response.write("<input type=button value=NEXT
onclick=""document.location.href='default.asp?Curpage=")
response.write( curpage + 1 & "&NumPerPage=" &
NumPerPage & "';"">")
End if
%>
</td>
<td>
<%
''LAST buton
Response.write("<input type=button value=LAST
onclick=""document.location.href='default.asp?Curpage=")
response.write( RecordSet.Pagecount
& "&NumPerPage=" & NumPerPage & "'"">")
%>
</td>
<td>
<input type="submit" method="post" value="SAVE"
name="btnUpdate" onClick="Return confirmsave()" title="Save this item">
</td>
<td>
<input type="submit" value="Search By Store
Number" name="FindButton">
</td>
<td>
<select size=1 name="FindIDText" >
<%
Dim sql2,Prod
Set Prod = server.createObject
("ADODB.Recordset")
sql2 = "SELECT * FROM stores Order By
stor_id desc"
prod.Open sql2,DataConnection
Do While Not Prod.EOF
response.write "<option>" & Prod
("stor_id") & "</option>"
prod.MoveNext
loop
%>
</select>
</td>
</table>
<% IF Updated = "True" Then %>
<b><%= RecordSet.Fields("stor_id") %></b>
<p> has been updated.</p>
<%End if %>
<%
'Set count to equal to zero
count = 0
Do while Not RecordSet.EOF and Count < RecordSet.PageSize
%>
<table>
<tr>
<td>
Store ID:
</td>
<td>
<input name="ID" type="hidden" value="<%
RecordSet.fields("stor_id")%>"><%= RecordSet.fields("stor_id") %>
</td>
</tr>
<tr>
<td colspan="4">
<hr>
</td>
</tr>
<tr>
<td>
Store Name:
</td>
<td>
<input type="text" name="stor_name" value="<%
RecordSet.fields("stor_name")%>">
</td>
<td>
Store Location:
</td>
<td>
<input type="text" name="city" value="<%
RecordSet.fields("city")%>">
</td>
</tr>
<%
count = count +1
RecordSet.movenext
loop
%>
</table>
</form>
</BODY>
</HTML>
<%
RecordSet.close
set RecordSet = Nothing
set cmdDC = Nothing
DataConnection.Close
SEt DataConnection = Nothing
%>
Message #6 by "Kim Iwan Hansen" <kimiwan@k...> on Sat, 30 Mar 2002 15:27:43 +0100
|
|
Try and response.write the sql string to the screen - so you can see what
the update part is doing.
'************* Updating Record ***************
if Request.form("btnUpdate") = "SAVE" Then
'gather form field values
stor_name = request.form("stor_name")
city = request.form("city")
'define the update query
strUpdate = "UPDATE stores set stor_name='"&stor_name&"',
city='"&city&"' WHERE stor_id="&id&""
********* take a look at the sql string *******
Response.Write(strUpdate)
Response.End
'**********************************************
'execute the update
cmdDC.Execute(strUpdate)
updated = "True"
End if
'**********************************************
-Kim
-----Original Message-----
From: Sonderman Fred W Contr OD4/DM
[mailto:Fred.Sonderman@O...]
Sent: 30. marts 2002 02:40
To: ASP Databases
Subject: [asp_databases] RE: Updating records
NO!!
-----Original Message-----
From: Kim Iwan Hansen [mailto:kimiwan@k...]
Sent: Friday, March 29, 2002 4:19 PM
To: ASP Databases
Subject: [asp_databases] RE: Updating records
But you figured out what the problem was now? :o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 17:07
To: ASP Databases
Subject: [asp_databases] RE: Updating records
Hi Kim,
I am not getting a message, and it is responding like it did do the
update. Oh, but no changes are being made. I I included all the code
because I am connecting up to the pubs database, and I thought it would be
helpful.
Thanks for taking the time to respond.
> - Got an error code?
- If you got one, did you look it up at google or microsoft's sites?
- Did you response.write the sql string out? (if so, try and post it)
- Etc.
Providing that kind of info will do more good than a couple hundred lines
of
wrapped asp code ;o)
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 29. marts 2002 09:14
To: ASP Databases
Subject: [asp_databases] Updating records
Hi all,
I am having problems getting the following script to save for me. I hope
somebody will notice something out of place.
Thanks in advance,
Bill
Message #7 by fred.sonderman@o... on Sat, 30 Mar 2002 18:51:41
|
|
Hi,
I added the write statement, and got the following back.
UPDATE stores set stor_name='Home Depot', city='Fremont' WHERE stor_id=7896
I also plugged my update statement in SQL Query Analyzer to see if it
would work. It did. I entered the following into QA;
use pubs
UPDATE stores set stor_name='Duke', city='Pismo Beach' WHERE stor_id=7131
Message #8 by "Kim Iwan Hansen" <kimiwan@k...> on Sat, 30 Mar 2002 21:00:00 +0100
|
|
Try and "SELECT * FROM stores WHERE stor_id = 7896" in QA.. just to see if
it contains a record with the stor_id in question.
-Kim
-----Original Message-----
From: fred.sonderman@o...
[mailto:fred.sonderman@o...]
Sent: 30. marts 2002 18:52
To: ASP Databases
Subject: [asp_databases] RE: Updating records
Hi,
I added the write statement, and got the following back.
UPDATE stores set stor_name='Home Depot', city='Fremont' WHERE stor_id=7896
I also plugged my update statement in SQL Query Analyzer to see if it
would work. It did. I entered the following into QA;
use pubs
UPDATE stores set stor_name='Duke', city='Pismo Beach' WHERE stor_id=7131
|
|
 |