-
Sql statement error
Hi Is there an error in my sql update statement here?
I am trying to read, adjust and write back to the same cell in a database. I think I can do it like this but i get an error on the executenonquery line.
Code:
Dim conn1 As New System.Data.OleDb.OleDbConnection(m_sConn2)
conn1.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand()
cmd.Connection = conn1
cmd.CommandText = "SELECT " & Night & " FROM TblContacts WHERE Phone='" & incomingtextno & "'"
Dim myOleDbCommand As New OleDbCommand(cmd.CommandText, cmd.Connection)
Using myDataReader As OleDbDataReader = myOleDbCommand.ExecuteReader()
If myDataReader.HasRows() Then
While myDataReader.Read()
current_count = myDataReader.Item(Night).ToString + vbCrLf
TxtEventLog.Text = current_count
current_count = current_count + Quantity
cmd.CommandText = "UPDATE TblContacts SET " & Night & "='" & current_count & "' Where Phone='" & incomingtextno & "'"
cmd.ExecuteNonQuery()
' index = index + 1
notfound = 0
End While
Else
notfound = 1
' Address_text.Text = "Not Found"
End If
End Using
con.Close()
-
Re: Sql statement error
What is the error message ?
-
Re: Sql statement error
The error is on the ExecuteNonQuery line and is
"Data type mismatch in criteria expression."
-
Re: Sql statement error
This could be the case where you include your values within '' which is not required. Use the parameters as suggested here