Problem updating fields

Results 1 to 8 of 8

Thread: Problem updating fields

  1. #1
    Join Date
    Dec 1969
    Posts
    36

    Default Problem updating fields

    Hello there, this is my first post here, so, hi everyone :)<BR><BR>Let me give ou some code before I explain, here&#039;s what I&#039;m using:<BR><BR> Set RS = Server.CreateObject("ADODB.Recordset")<BR> <BR> Dim username<BR> username = Session("username")<BR> <BR> strSQL = ("SELECT * FROM users WHERE username=" & username &"")<BR> RS.open strSQL, objConn, 1, 3<BR> RS("username") = strUsername<BR> RS("password") = strPassword<BR> RS.update<BR><BR>This is from a page that processes a form where the user can change his username and password. "strUsername" and "strPassword" are variables that contain the information entered in the form.<BR><BR>This is the error I&#039;m getting:<BR><BR>Error Type:<BR>Microsoft JET Database Engine (0x80040E10)<BR>No value given for one or more required parameters.<BR><BR>..and it points to this line:<BR> RS.open strSQL, objConn, 1, 3<BR>..but the strange thing is, I&#039;m using this exact same code (only different vars) on some other page and it works perfectly...!<BR>I really can&#039;t see what&#039;s happening, can anyone help? Is there a better way to update these fields?<BR><BR>Thanks a lot,<BR>André Bergonzzi

  2. #2
    Join Date
    Dec 1969
    Posts
    72

    Default RE: Problem updating fields

    I think you are just making a small error in the syntax, try adding .value to the code. hmm.. look below<BR><BR>strSQL = ("SELECT * FROM users WHERE username=" & username &"")<BR>RS.open strSQL, objConn, 1, 3<BR>RS("username").value = strUsername<BR>RS("password").value = strPassword<BR>RS.update<BR><BR>I believe that this is the way you update in this method. When you want to add a new entry you do it the way you have but add the RS.AddNew to the top of it. Hope this helps you out in some way.<BR><BR>Stephen Little<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    36

    Default RE: Problem updating fields

    Well actually it doesn&#039;t work either! I had tried it already... I also tried:<BR><BR> RS.Fields("username") = strUsername<BR> RS.Fields("password") = strPassword<BR> RS.update<BR><BR>and yet..<BR><BR> RS.Fields("username").Value = strUsername<BR><BR>The problem is somewhere else I guess, because no matter the changes I do the error keeps pointing to this line:<BR><BR> RS.open strSQL, objConn, 1, 3<BR><BR>Could it be from the SELECT query? Now check this piece of code - it works perfectly:<BR><BR> Set RS = Server.CreateObject("ADODB.Recordset")<BR> strSQL = ("SELECT * FROM registos WHERE ID=" & strID & "")<BR> RS.open strSQL, objConn, 1, 3<BR> RS("campo1") = strCampo1<BR> RS("campo2") = strCampo2<BR> RS("data") = data<BR> RS.update<BR><BR>I also thought it could be from the database connection, but I&#039;m using an include file for it in all my .asp pages... and if it works on the other pages it should work on this one too! Anyway, just to check it out I have also tried putting the database connection code on the page itself, but the same error shows up.<BR><BR>I really really don&#039;t know why!<BR><BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    72

    Default RE: Problem updating fields

    What database are you using? Access?<BR>Try this maybe<BR>Set RS = Server.CreateObject("ADODB.Recordset")<BR>strSQL = "SELECT * FROM registos WHERE ID=" & strID <BR>Response.Write strSQL<BR>RS.open strSQL, objConn, 1, 3<BR>RS("campo1").value = strCampo1<BR>RS("campo2").value = strCampo2<BR>RS("data") = data<BR>RS.update<BR><BR><BR>Add in that response code so that you can see what your SQL statment looks like. Then you can be sure that the problem is not there.


  5. #5
    Join Date
    Dec 1969
    Posts
    2,437

    Default Missing quotes

    Your select statement should look like <BR><BR>strSQL = "SELECT * FROM users WHERE username=&#039;" & username &"&#039;"<BR><BR><BR>I would also recommend that you use an update statement instead of using the update method in ADO.<BR><BR>objConn.execute "update users set [password] = &#039;" & password & "&#039; where username = &#039;" & username & "&#039;",,128<BR><BR>That is all you need.

  6. #6
    Join Date
    Dec 1969
    Posts
    36

    Default RE: Problem updating fields

    I did that what you suggested, and the query seems to be ok.<BR>So, if it&#039;s not the query and it&#039;s not the connection object, what else could it be?<BR><BR>Can you tell me some other way to update certain fields in table? Maybe doing it directly by using the Execute method of the connection object or something...

  7. #7
    Join Date
    Dec 1969
    Posts
    36

    Default RE: Missing quotes

    Lars, thanks for the help but I couldn&#039;t get it to work...! I&#039;m really sorry, this is probably something very simple, but I&#039;m with ASP for no more that a week or so!<BR><BR>Tell me, if I use the objConn.execute (...) I don&#039;t need to use the SELECT statement anymore right?<BR>And, what does that ,,128 mean? Maybe if you give me a real example it would be easier.<BR><BR>By the way, could you point me out to some page that sorts out these syntax issues? I never know when to use " or &#039; or () or even & ...!<BR><BR>Thanks a lot for any help!

  8. #8
    Join Date
    Dec 1969
    Posts
    72

    Default RE: Problem updating fields

    I would then suggest that you use "Response.Write" to see if you are givning your var. values. <BR><BR>Stephen Little

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •