3 Replies - 447 Views - Last Post: 27 December 2012 - 09:01 AM Rate Topic: -----

#1 sanblue  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-December 12

update syntax error in vb.net

Posted 27 December 2012 - 01:07 AM

cmd.CommandText = "UPDATE master SET appl_no='" & Me.app_id.Text & _
                        ", c_name='" & Me.app_name.Text & "'" & _
                        ", h_f_m_name='" & Me.appfm_name.Text & "'" & _
                        " WHERE appl_no=" & Me.app_id.Tag
            cmd.ExecuteNonQuery()

This post has been edited by AdamSpeight2008: 27 December 2012 - 05:35 PM

Is This A Good Question/Topic? 0
  • +

Replies To: update syntax error in vb.net

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: update syntax error in vb.net

Posted 27 December 2012 - 01:41 AM

You need to correct ' apostrophes in that query, and use them on both side of values. For example: appl_no='" & Me.app_id.Text & ", c_name... See there's no ' behind & ", c_name. Should be & "', c_name.
Was This Post Helpful? 0
  • +
  • -

#3 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: update syntax error in vb.net

Posted 27 December 2012 - 01:44 AM

this is the proper way for update command if u are using sql server.....empdata is my tablename... txtdata is my database...empcon my sqlconnection name.

Private Sub modify()
        empcmd.CommandText = " update txtdata.dbo.empdata set emp_code = " & txtempcode.Text & " , emp_name = '" & _
         txtempname.Text & "' , emp_sname = '" & txtempsname.Text & "' , emp_fname = '" & _
         txtempfname.Text & "' , emp_dob = '" & DateValue(txtempdob.Text).ToString("MM/dd/yyyy") & _
         "' , emp_doj ='" & DateValue(txtempdoj.Text).ToString("MM/dd/yyyy") & "' where emp_key = " & txtempkey & ""

        empcon.Open()   ' open connection
        empcmd.Connection = empcon
        empcmd.ExecuteNonQuery()  
        empcon.Close()  ' close connection

       


This post has been edited by kai_itz me: 27 December 2012 - 01:46 AM

Was This Post Helpful? 0
  • +
  • -

#4 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,461
  • Joined: 07-April 08

Re: update syntax error in vb.net

Posted 27 December 2012 - 09:01 AM

you should use Parameterized statements instead of inlining your SQL. You set yourself up for risk of SQL Injection the way you currently are doing it.

EX:

com.CommandText = "UPDATE <Table> SET Col1 = @Col1, Col2 = @Col2"

com.Parameters.AddWithValue("@Col1",txtTextBox.Text)
com.Parameters.AddWithValue("@Col2",txtTextBox2.Text)



Was This Post Helpful? 1
  • +
  • -

Page 1 of 1