Wrox Programmer Forums
|
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
 
Old October 20th, 2004, 04:04 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>
 
Old October 20th, 2004, 10:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old October 21st, 2004, 01:37 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.



 
Old October 21st, 2004, 11:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old October 22nd, 2004, 01:14 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old October 24th, 2004, 07:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Why don't you try this? Replace the following with this
Code:
myRs.Requery
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
 
Old October 25th, 2004, 06:24 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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??


 
Old October 25th, 2004, 07:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Did you try CLOSE and OPEN as mentioned in my previous post? Did that help?

_________________________
- Vijay G
Strive for Perfection
 
Old October 25th, 2004, 07:30 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I did but. Nothing happens. The variables must be the problem.


 
Old October 25th, 2004, 08:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
update a fields value Vince_421 Access VBA 2 May 19th, 2006 06:41 AM
Update Table fields karajian Access VBA 2 December 7th, 2004 03:48 PM
Update multiple fields. slgknjn Classic ASP Databases 6 February 15th, 2004 10:26 AM
fields from tables to update damnnono_86 Access 3 November 5th, 2003 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.