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. Database & SysAdmin
  3. Database
  4. ERROR ON UPDATE QUERY

ERROR ON UPDATE QUERY

Scheduled Pinned Locked Moved Database
helpdatabasecomquestionannouncement
12 Posts 6 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.
  • S Sadaf Naeem

    the code in my application is: OleDbCommand com = new OleDbCommand(); com.Connection = con; com.CommandText = "UPDATE tblUsers SET Password=? WHERE UserName=?"; com.Parameters.Add("UserName", OleDbType.WChar); com.Parameters.Add("Password", OleDbType.WChar); com.Parameters["UserName"].Value = this.UserName; com.Parameters["Password"].Value = this.txtPassword1.Text; ------------------------------------------------------------------------------- When I run the application , it gives the syntax error in update query. I am unable to find where I am going wrong Kindly help me!

    Sadaf

    K Offline
    K Offline
    Khawar Abbas1
    wrote on last edited by
    #2

    Why not you try this: com.CommandText = "UPDATE tblUsers SET Password='" + this.UserName.Text + "' WHERE UserName='" + this.txtPassword1.Text + "'"

    Do good and have good.

    P 1 Reply Last reply
    0
    • K Khawar Abbas1

      Why not you try this: com.CommandText = "UPDATE tblUsers SET Password='" + this.UserName.Text + "' WHERE UserName='" + this.txtPassword1.Text + "'"

      Do good and have good.

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #3

      Silent Eagle wrote:

      com.CommandText = "UPDATE tblUsers SET Password='" + this.UserName.Text + "' WHERE UserName='" + this.txtPassword1.Text + "'"

      Shouldn't that be: com.CommandText = "UPDATE tblUsers SET Password='" + this.txtPassword1.Text + "' WHERE UserName='" + this.UserName.Text + "'"

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      K S 2 Replies Last reply
      0
      • P pmarfleet

        Silent Eagle wrote:

        com.CommandText = "UPDATE tblUsers SET Password='" + this.UserName.Text + "' WHERE UserName='" + this.txtPassword1.Text + "'"

        Shouldn't that be: com.CommandText = "UPDATE tblUsers SET Password='" + this.txtPassword1.Text + "' WHERE UserName='" + this.UserName.Text + "'"

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        K Offline
        K Offline
        Khawar Abbas1
        wrote on last edited by
        #4

        Thanks, Yes you are right. It is written mistakenly but i think it conveys the concept.

        Do good and have good.

        1 Reply Last reply
        0
        • P pmarfleet

          Silent Eagle wrote:

          com.CommandText = "UPDATE tblUsers SET Password='" + this.UserName.Text + "' WHERE UserName='" + this.txtPassword1.Text + "'"

          Shouldn't that be: com.CommandText = "UPDATE tblUsers SET Password='" + this.txtPassword1.Text + "' WHERE UserName='" + this.UserName.Text + "'"

          Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

          S Offline
          S Offline
          Sadaf Naeem
          wrote on last edited by
          #5

          Thanks all for ur kind help but its still giving the same error!

          Sadaf

          P 1 Reply Last reply
          0
          • S Sadaf Naeem

            the code in my application is: OleDbCommand com = new OleDbCommand(); com.Connection = con; com.CommandText = "UPDATE tblUsers SET Password=? WHERE UserName=?"; com.Parameters.Add("UserName", OleDbType.WChar); com.Parameters.Add("Password", OleDbType.WChar); com.Parameters["UserName"].Value = this.UserName; com.Parameters["Password"].Value = this.txtPassword1.Text; ------------------------------------------------------------------------------- When I run the application , it gives the syntax error in update query. I am unable to find where I am going wrong Kindly help me!

            Sadaf

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

            try this code OleDbCommand com = new OleDbCommand(); com.Connection = con; com.CommandText = "UPDATE tblUsers SET Password=? WHERE UserName=?"; com.Parameters.Add("UserName", OleDbType.WChar); com.Parameters.Add("Password", OleDbType.WChar); com.Parameters["UserName"].Value = this.UserName.Text;//Error was here com.Parameters["Password"].Value = this.txtPassword1.Text;

            1 Reply Last reply
            0
            • S Sadaf Naeem

              the code in my application is: OleDbCommand com = new OleDbCommand(); com.Connection = con; com.CommandText = "UPDATE tblUsers SET Password=? WHERE UserName=?"; com.Parameters.Add("UserName", OleDbType.WChar); com.Parameters.Add("Password", OleDbType.WChar); com.Parameters["UserName"].Value = this.UserName; com.Parameters["Password"].Value = this.txtPassword1.Text; ------------------------------------------------------------------------------- When I run the application , it gives the syntax error in update query. I am unable to find where I am going wrong Kindly help me!

              Sadaf

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #7

              try this com.CommandText = "UPDATE tblUsers SET [Password]='" + this.txtPassword1.Text + "' WHERE [UserName]='" + this.UserName.Text + "'"


              I Love SQL

              P 1 Reply Last reply
              0
              • S Sadaf Naeem

                Thanks all for ur kind help but its still giving the same error!

                Sadaf

                P Offline
                P Offline
                pmarfleet
                wrote on last edited by
                #8

                There are two major flaws in your code: 1. Generating SQL statements on the fly is generally considered bad practice. It leaves you exposed to SQL injection attacks. Instead, consider writing a stored procedure to perform your update and call it from your .NET code. 2. You appear to be storing your user's passwords in clear text. This is very insecure. You should consider encrypting your password using a 1-way salted hash algorithm.

                Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

                1 Reply Last reply
                0
                • B Blue_Boy

                  try this com.CommandText = "UPDATE tblUsers SET [Password]='" + this.txtPassword1.Text + "' WHERE [UserName]='" + this.UserName.Text + "'"


                  I Love SQL

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #9

                  No. Don't do this. Haven't you heard of SQL Injection Attacks? Have a read through the many wonderful articles before you find out why this is wrong, oh so wrong.

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  B 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    No. Don't do this. Haven't you heard of SQL Injection Attacks? Have a read through the many wonderful articles before you find out why this is wrong, oh so wrong.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    B Offline
                    B Offline
                    Blue_Boy
                    wrote on last edited by
                    #10

                    Sure I have attention about SQL injection attacks...


                    I Love SQL

                    P 1 Reply Last reply
                    0
                    • B Blue_Boy

                      Sure I have attention about SQL injection attacks...


                      I Love SQL

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #11

                      If you are aware about SQL Injection Attacks, then why do you recommend something that is wide open to such an attack? It's your responsibility when posting an answer to give good advice and not to post something that is such blatant bad practice.

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      B 1 Reply Last reply
                      0
                      • P Pete OHanlon

                        If you are aware about SQL Injection Attacks, then why do you recommend something that is wide open to such an attack? It's your responsibility when posting an answer to give good advice and not to post something that is such blatant bad practice.

                        Deja View - the feeling that you've seen this post before.

                        My blog | My articles

                        B Offline
                        B Offline
                        Blue_Boy
                        wrote on last edited by
                        #12

                        but it's not my responsibility to teach others about SQL injection all of programmers must know about SQL injections... Why you not gonna explain him about SQL injections?


                        I Love SQL

                        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