Data type mismatch in criteria expression

后端 未结 2 1184
梦谈多话
梦谈多话 2021-01-27 18:01
 myConnection.Open()
    rtb_Address.Clear()
    txt_Name.Clear()
    Dim str As String
    str = \"SELECT * FROM table1 WHERE (cus_ID = \'\" & txt_ID.Text & \"\         


        
相关标签:
2条回答
  • 2021-01-27 18:40

    I would recommend the following:

     Using cmd As New OleDbCommand("SELECT * FROM table1 WHERE cus_ID = @ID", con)
        cmd.Parameters.AddWithValue("@ID", txt_ID.Text)
    
        dr = cmd.ExecuteReader()
    
        While dr.Read()
          rtb_Address.Text = dr("cus_Addr").ToString
          txt_Name.Text = dr("cus_Name").ToString
        End While
    
     End Using
    
    0 讨论(0)
  • 2021-01-27 18:48

    cus_ID is probaly a numeric data type, but you try to query it with a string: (cus_ID = 'thevalue').

    Just remove the enclosing ': (cus_ID = thevalue)

    or better, use a parameterized query to prevent sql-injection.

    0 讨论(0)
提交回复
热议问题