Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Update command..plz urgnt

Update command..plz urgnt

Scheduled Pinned Locked Moved C#
databasehelpannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    r_e_h_a_n
    wrote on last edited by
    #1

    Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir

    D S 3 Replies Last reply
    0
    • R r_e_h_a_n

      Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir

      D Offline
      D Offline
      da vinci coder
      wrote on last edited by
      #2

      that means there is a syntax error at the query string.. just show code and maybe there would be some help.. good coding

      R 1 Reply Last reply
      0
      • R r_e_h_a_n

        Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir

        S Offline
        S Offline
        StevenS_Dev
        wrote on last edited by
        #3

        An example of what you are doing will be helpful. Did you remember to put quotes around the passwords? It should look something like this: UPDATE usertable SET password = 'newpassword' WHERE password = 'oldpassword'; When creating the UPDATE string, you will need to surround your password variables with the single quote. That is the only thing I can think of which may be causing the problem. I sometimes find it helpful to use a SQL Editor for creating my SQL statements. It saves me a bunch of time from having to try and retry different commands through code. I don't use MSAccess so I am not sure what type of GUI editor they may have.

        R 1 Reply Last reply
        0
        • S StevenS_Dev

          An example of what you are doing will be helpful. Did you remember to put quotes around the passwords? It should look something like this: UPDATE usertable SET password = 'newpassword' WHERE password = 'oldpassword'; When creating the UPDATE string, you will need to surround your password variables with the single quote. That is the only thing I can think of which may be causing the problem. I sometimes find it helpful to use a SQL Editor for creating my SQL statements. It saves me a bunch of time from having to try and retry different commands through code. I don't use MSAccess so I am not sure what type of GUI editor they may have.

          R Offline
          R Offline
          r_e_h_a_n
          wrote on last edited by
          #4

          "This is my code now plz help me according to this code" here "password" is the field of database;" OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\SMSDB.mdb;Persist Security Info=False"); con.Open(); string updata = "update SMSDB set password= '"+txtnewpwd.Text+"' where password='"+txtoldpwd.Text+"'"; OleDbTransaction tx = con.BeginTransaction(); tx.Commit(); OleDbCommand cmd = new OleDbCommand(updata,con); cmd.ExecuteNonQuery(); con.Close(); m.reehanmunir

          1 Reply Last reply
          0
          • D da vinci coder

            that means there is a syntax error at the query string.. just show code and maybe there would be some help.. good coding

            R Offline
            R Offline
            r_e_h_a_n
            wrote on last edited by
            #5

            "this is my code now plz help me according to this" here "password" is database field;" thx OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\SMSDB.mdb;Persist Security Info=False"); con.Open(); string updata = "update SMSDB set password= '"+txtnewpwd.Text+"' where password='"+txtoldpwd.Text+"'"; OleDbTransaction tx = con.BeginTransaction(); tx.Commit(); OleDbCommand cmd = new OleDbCommand(updata,con); cmd.ExecuteNonQuery(); con.Close(); m.reehanmunir

            1 Reply Last reply
            0
            • R r_e_h_a_n

              Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir

              S Offline
              S Offline
              StevenS_Dev
              wrote on last edited by
              #6

              It is not necessary to create a transaction. Transactions are used when you plan on doing several SQL calls and there is the possibility of a problem. If there is a problem, a transaction lets you rollback any change prior to anything being fully committed to the database. In the case of the password, you have the one SQL statement and probably do not want it in a transaction. If you did want a transaction, the commit will need to be AFTER your Execute call. As it is, the Transaction in the code is not doing anything and can probably be removed. Try putting a space between password and the '='.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups