|
-
Aug 10th, 2011, 06:55 AM
#1
Thread Starter
Hyperactive Member
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()
-
Aug 10th, 2011, 07:19 AM
#2
Re: Sql statement error
What is the error message ?
Please mark you thread resolved using the Thread Tools as shown
-
Aug 10th, 2011, 07:38 AM
#3
Thread Starter
Hyperactive Member
Re: Sql statement error
The error is on the ExecuteNonQuery line and is
"Data type mismatch in criteria expression."
-
Aug 10th, 2011, 07:42 AM
#4
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
Please mark you thread resolved using the Thread Tools as shown
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|