 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 20th, 2004, 04:04 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problem to update fields
I´m trying to update fields. But nothing happens and I don´t get a eroro message.
It´s the case "Uppdatera" how is the problem.
Can anyone help me, please.
Code:
<%
Option Explicit
Dim btnClicked
Dim myConn
Dim myRs
Dim collitem
Dim vParameter
Dim myParam
Dim vMoveNumber
Dim vCUSTOMERNAME
Dim vCUSTOMERNAMEn
Dim vUSER_ID
Dim vUSER_IDn
Dim intI
Dim vRecordToDelete
Dim SQL
%>
<html>
<head>
<title>Recordsetet</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<H2>Visar innehåll från tabellen Customer</H2>
<TABLE border=0>
<TR><TD>
<H2></H2>
</TD></TR><TR><TD bgcolor="white">
<%
btnClicked = Request.Form("btnval")
Select Case btnClicked
Case "Lägg till"
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open "DSN=CPRCT;UID=" & session("anvid") & ";PWD=" & session("password") & ""
Set myRs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM TEST.Customer"
myRS.Open SQL,myConn,1,2
myRs.AddNew
myRs.Fields("CUSTOMERNAME")=request.form("CUSTOMERNAME")
myRs.Fields("USER_ID")=request.form("USER_ID")
myRs.Update
'myRs.Requery
Response.Write "<TABLE border=0>"
Do While not myRs.EOF
Response.Write "<TR><TD><B>Du har lagt till:</b></td></tr>"
Response.Write "<TR><TD><B>Kundnamn " & myRs.Fields("CUSTOMERNAME") & "</b></TD><TD><b>Användarid " & myRs.Fields("USER_ID")&"</B></TD></TR>"
myRs.MoveNext
Loop
Response.Write "</table>"
Set myRs = Nothing
Set myConn = Nothing
Case "Visa rader"
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open "DSN=CPRCT;UID=" & session("anvid") & ";PWD=" & session("password") & ""
Set myRs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM TEST.Customer"
myRS.Open SQL,myConn,3,3
%>
<Form Method=Post Action="Customer.asp"><Table>
<%
Do While not myRs.EOF
%>
<TR><TD><B>Kundid <INPUT TYPE="text" name="CUID<% Response.Write myRs.Fields("CUID") %>" value="<% Response.Write myRs.Fields("CUID") %>"></B></TD>
<TD><B>Kundnamn <INPUT TYPE="text" name="CUSTOMERNAME<% Response.Write myRs.Fields("CUID") %>" value="<% Response.Write myRs.Fields("CUSTOMERNAME") %>"></B></TD>
<TD><B>Användarid <INPUT TYPE="text" name="USER_ID<% Response.Write myRs.Fields("CUID") %>" value ="<% Response.Write myRs.Fields("USER_ID") %>"></B></TD><TR>
<%
myRs.MoveNext
Loop
%>
<TR><TD COLSPAN=3><INPUT TYPE="submit" name="btnval" value="Uppdatera">
</TD></TR></Form></Table>
<%
Set myRs = Nothing
Set myConn = Nothing
Case "Uppdatera"
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open "DSN=CPRCT;UID=" & session("anvid") & ";PWD=" & session("password") & ""
Set myRs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM TEST.Customer"
myRS.Open SQL,myConn,3,4
Do While not myRs.EOF
vCUSTOMERNAMEn = "CUSTOMERNAME" & myRs.Fields("CUID")
vCUSTOMERNAME = request.form(vCUSTOMERNAMEn)
vUSER_IDn = "USER_ID" & myRs.Fields("CUID")
vUSER_ID = request.form(vUSER_IDn)
myRs.Fields("CUSTOMERNAME") = vCUSTOMERNAME
myRs.Fields("USER_ID") = vUSER_ID
myRs.Update
myRs.MoveNext
Loop
myRs.Requery
%>[/blue] <Form Method=Post Action="Customer.asp"><Table><TR><TD><B>Kundid</B></TD><TD><B>Kundnamn</B></TD><TD><B>Användarid</B></TD><TD><B>Ta bort?</B></TD></TR>
<%
Do While not myRs.EOF
%>
<TR><TD><INPUT TYPE="text" name="CUID<% Response.Write myRs.Fields("CUID") %>" value="<% Response.Write myRs.Fields("CUID") %>"></TD>
<TD><INPUT TYPE="text" name="CUSTOMERNAME<% Response.Write myRs.Fields("CUID") %>" value ="<% Response.Write myRs.Fields("CUSTOMERNAME") %>"></TD>
<TD><INPUT TYPE="text" name="USER_ID<% Response.Write myRs.Fields("CUID") %>" value = "<% Response.Write myRs.Fields("USER_ID") %>"></B></TD>
<TD><INPUT TYPE="checkbox" name="chkbx<% Response.Write myRs.Fields("CUID") %>"></TD></TR>
<%
myRs.MoveNext
Loop
%>
<TR><TD COLSPAN=3><INPUT TYPE="submit" name="btnval" value="Uppdatera">
<INPUT TYPE="submit" name="btnval" value="Ta bort rad"></TD></TR></Form></Table>
<%
Set myRs = Nothing
Set myConn = Nothing
Case "Ta bort rad"
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open "DSN=CPRCT;UID=" & session("anvid") & ";PWD=" & session("password") & ""
Set myRs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM TEST.Customer"
myRS.Open SQL,myConn,3,4
For Each collitem in Request.Form
If Left(collitem, 5) = "chkbx" Then
vRecordToDelete = Mid(collitem, 6, 10)
myRs.Find "CUID = " & vRecordToDelete & ""
If myRs.BOF Then
Response.Write "Raden " & vRecordToDelete & " hittades ej.<BR>"
Else
If myRs.EOF Then
Response.Write "Raden " & vRecordToDelete & " hittades ej.<BR>"
Else
myRs.Delete
Response.Write "Raden " & vRecordToDelete & " togs bort.<BR>"
End If
End If
End If
Next
myRs.Requery
%>
<Form Method=Post Action="Customer.asp"><Table><TR><TD><B>Kundid</B></TD><TD><B>Kundnamn</B></TD><TD><B>Användarid</B></TD><TD><B>Ta bort?</B></TD></TR>
<%
Do While not myRs.EOF
%>
<TR>
<TD><INPUT TYPE="text" name="CUID<% Response.Write myRs.Fields("CUID") %>" value="<% Response.Write myRs.Fields("CUID") %>"></TD>
<TD><INPUT TYPE="text" name="CUSTOMERNAME<% Response.Write myRs.Fields("CUID") %>" value ="<% Response.Write myRs.Fields("CUSTOMERNAME") %>"></TD>
<TD><INPUT TYPE="text" name="USER_ID<% Response.Write myRs.Fields("CUID") %>" value = "<% Response.Write myRs.Fields("USER_ID") %>"></TD>
<TD><INPUT TYPE="checkbox" name="chkbx<% Response.Write myRs.Fields("CUID") %>"></TD></TR>
<%
myRs.MoveNext
Loop
%>
<TR><TD COLSPAN=3><INPUT TYPE="submit" name="btnval" value="Uppdatera">
<INPUT TYPE="submit" name="btnval" value="Ta bort rad"></TD></TR></Form></Table>
<%
Set myRs = Nothing
Set myConn = Nothing
End Select
%>
</TD></TR></TABLE>
<P>
<TABLE border=0 width="80%">
<TR>
<TD bgcolor="#FFFFFF" COLSPAN=3>
<H3></H3>
</TD>
</TR>
<TR>
<TD colspan="3">
<form method=POST action="Customer.asp">
</TD>
</TR>
<TR>
<TD colspan="3">
<table width="100%" border="0">
<tr>
<td><b>Flytta genom rekordsetet</b>
<input type="submit" name="btnval" value="Första" ID="Submit1">
<input type="submit" name="btnval" value="Föregående" ID="Submit2">
<input type="submit" name="btnval" value="Nästa" ID="Submit3">
<input type="submit" name="btnval" value="Sista" ID="Submit4">
<input type="submit" name="btnval" value="Flytta" ID="Submit5">
<input type="text" name="MoveNumber" size="5" ID="Text1">
</td>
</table>
</TD>
</TR>
<TR>
<TD colspan="3">
<table width="100%" border="0">
<tr>
<td><B>Lägg till kund - Kundnamn</B>
<input type="text" name="CUSTOMERNAME" size="10">
<B>Användarid</B>
<input type="text" name="USER_ID" size="10"><b>
<input type="submit" name="btnval" value="Lägg till">
</td>
</tr>
</table>
</TD>
</TR>
<TR>
<TD colspan="3">
<table width="100%" border="0">
<tr>
<td><B>Visa rader för uppdatering</B>
<input type="submit" name="btnval" value="Visa rader">
</td>
</tr>
</table>
</TD>
</TR>
</form>
</TR>
</TABLE>
</BODY>
</HTML>
|
|

October 20th, 2004, 10:04 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Cilla,
That is because, you were using "RESPONSE.WRITE" which should have been "=" in the following code within that case.
Code:
Do While not myRs.EOF
%>
<TR><TD><INPUT TYPE="text" name="CUID<%= myRs.Fields("CUID") %>" value="<%= myRs.Fields("CUID") %>"></TD>
<TD><INPUT TYPE="text" name="CUSTOMERNAME<%=myRs.Fields("CUID") %>" value ="<%=myRs.Fields("CUSTOMERNAME") %>"></TD>
<TD><INPUT TYPE="text" name="USER_ID<%=myRs.Fields("CUID") %>" value = "<%=myRs.Fields("USER_ID") %>"></B></TD>
<TD><INPUT TYPE="checkbox" name="chkbx<%=myRs.Fields("CUID") %>"></TD></TR>
<%
myRs.MoveNext
Loop
Now that should work. Also Did you try a response.write of those dynamic Variables before assigning to Recordset variables? That should have pointed you in the right direction.
Code:
vCUSTOMERNAMEn = "CUSTOMERNAME" & myRs.Fields("CUID")
Code:
vCUSTOMERNAME = request.form(vCUSTOMERNAMEn)
vUSER_IDn = "USER_ID" & myRs.Fields("CUID")
vUSER_ID = request.form(vUSER_IDn)
Response.write vCUSTOMERNAME & "---" & vUSER_ID & "<BR>"
myRs.Fields("CUSTOMERNAME") = vCUSTOMERNAME
myRs.Fields("USER_ID") = vUSER_ID
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

October 21st, 2004, 01:37 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,thanks for your replay
I sorry to say that the I still have the problem.
I thought that Rsponse.Write rs.field("X") and =rs.field("X")
is the same thing?
The problem is that a get my value from the input boxes in the case before "Uppdatera" if I change one value I get this value with me, but it stops with that. I don´t get into the next loop with the inputboxes who are in this case. Theses inputboxes don´t updats.
|
|

October 21st, 2004, 11:03 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
There is a difference between those two in your case.
<%Response.Write rs.field("X")%> 'Displays the value on the page
<%=rs.field("X")%> ' Substitutes the value in its place
I really don't understand where you are stuck up with. Can you explain on what exactly the issue is. And why is there a CHECKBOX used within case "Uppdatera"?
Have you replaced RESPONSE.WRITE with = in all INPUT boxes, under all cases?
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

October 22nd, 2004, 01:14 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
thanks for your help. Yes, I have changed to = on all input boxes.
I have put a checkbox here because in my next case it should be possible to delete a record.
The problem is how I pick up the changes of records of the inputboxes, in the case before and do the update. It seem that the update don´t happen and myRs.Requery gets the old data back again.
Probably I do this wrong because I not so good at programming.
/Cilla
|
|

October 24th, 2004, 07:17 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Why don't you try this? Replace the following with this
Code:
myRS.Close
myRS.Open SQL,myConn,3,4
Which is the same as that of REQUERY. See if that helps.
Also as I said in my previous second post, did you try the response.write to see if the values come fine?
Code:
Response.write "Before Update - " & vCUSTOMERNAME & "--" & vUSER_ID & "<br>"
myRs.Fields("CUSTOMERNAME") = vCUSTOMERNAME
myRs.Fields("USER_ID") = vUSER_ID
myRs.Update
Response.write "After Update - " & myRs.Fields("CUSTOMERNAME") & "--" & myRs.Fields("USER_ID") & "<br>"
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

October 25th, 2004, 06:24 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The problem is my variables when I wite them out it seem that I get the value out twice. Like this
Before update - --
After update - hallo --toyou // The first record
Before update - hallo--toyou
After update - www --website // The second record
Before update - www--website
After update - cilla --ci // The third record
Before update - cilla --ci
Any idear??
|
|

October 25th, 2004, 07:02 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Did you try CLOSE and OPEN as mentioned in my previous post? Did that help?
_________________________
- Vijay G
Strive for Perfection
|
|

October 25th, 2004, 07:30 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes I did but. Nothing happens. The variables must be the problem.
|
|

October 25th, 2004, 08:01 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Do you see the updated values in the database by anychance? Just to confirm, On the page, do you still see the old values or nothing gets displayed after update?
Also can you post the code within the while loop that comes after my.rsUPDATE? Let me see if you are missing something.
_________________________
- Vijay G
Strive for Perfection
|
|
 |