About Insert Into query using where clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vabh
    New Member
    • Feb 2008
    • 9

    About Insert Into query using where clause

    I am using access connection like-[code=vb]
    a = TextBox2.Text.R emove(1)
    a = TextBox2.Text.R emove(1)
    c = TextBox3.Text.R emove(1)
    b = TextBox4.Text
    TextBox5.Text = a + c + " " + b
    Dim com As New OleDbCommand("I NSERT INTO Employees(Code) VALUES(@cd) WHERE Sr_No='" & TextBox1.Text & "'", Connect.OledbCo nnection())
    com.Parameters. AddWithValue("@ cd", TextBox5.Text)
    com.Connection. Open()
    com.ExecuteNonQ uery()
    com.Connection. Close()
    MsgBox("OK")
    'Catch ex As Exception
    ' MsgBox(ex.Messa ge)
    'End Try[/code]
    but there is a problem inwhere clause it is giving me error as "Missing semicolon (;) in SQL statement...
    Is there any solution for that ?
    Last edited by debasisdas; Mar 13 '08, 12:08 PM. Reason: added code=vb tags
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    You will get the error if any of the Textboxes have a Single or Double Quote..
    ' Or "

    Before updation you have to check, and remove those chars..

    REgards
    Veena
    Last edited by debasisdas; Mar 13 '08, 12:08 PM. Reason: typo

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Why using where clause in insert into statement ?

      Either remove the where clause of use Update statemnet.

      Comment

      Working...