Syntax error in SQL update string

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 8
Reputation: nanoh2001 is an unknown quantity at this point 
Solved Threads: 0
nanoh2001 nanoh2001 is offline Offline
Newbie Poster

Syntax error in SQL update string

 
0
  #1
Jun 9th, 2009
Hi all

Sorry- The title was wrong, My problem is when I type a the ID number in the text box for updating the record, it gives me an error "Data type mismatch in criteria expression."

Could anyone help me please in solving this problem?

This is my update code.


  1. cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\HRIS.mdb;")
  2. cn.Open()
  3. Dim strupdate As String
  4.  
  5. strupdate = "update Employees set [Name] ='" & txtName.Text & "',Mobile ='" & txtMob.Text & "',Home_Phn ='" & txtHomePhn.Text & "',Date_Birth ='" & txtAge.Text & "',CPR='" & txtCPR.Text & _
  6. "', Address='" & txtAdd.Text & "',email='" & txtEmail.Text & "',Date_hiring='" & txtWorkDate.Text & "',Department='" & txtDep.Text & "',basic_salary='" & txtSal.Text & "'where ID='" & txtSearch.Text & "'"
  7.  
  8. cmd = New OleDbCommand(strupdate, cn)
  9. cmd.ExecuteNonQuery()
  10. cn.Close()




Thanks in Advance
Last edited by nanoh2001; Jun 9th, 2009 at 3:18 pm. Reason: wrong title and case
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 12
Reputation: Vandamn is an unknown quantity at this point 
Solved Threads: 0
Vandamn's Avatar
Vandamn Vandamn is offline Offline
Newbie Poster

Re: Syntax error in SQL update string

 
0
  #2
Jun 9th, 2009
Hi nanoh2001,

I believe your problem is the fact that you are trying to update all fields in your table with string values. If the fields in the table are not all strings then you will get the error you are geting.

I notice that there is a date field you are updating. If this field is a date field and the value you are supplying is not in a valid date format, then the error you are gettting will be generated.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 8
Reputation: nanoh2001 is an unknown quantity at this point 
Solved Threads: 0
nanoh2001 nanoh2001 is offline Offline
Newbie Poster

Re: Syntax error in SQL update string

 
0
  #3
Jun 9th, 2009
Dear Vandamn,

Thanks for your fast valuable response. I'm sure that I put valid date entries in both birthdate and hiring date,

Yes you are right, I think vb considers any input from textboxes as string, but what can I do?

How can I solve this problem? I tried to convert the "ID" to intiger in "Delete record code form" using Cint function but it doesn't work
it gave me the same error,

please help
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 12
Reputation: Vandamn is an unknown quantity at this point 
Solved Threads: 0
Vandamn's Avatar
Vandamn Vandamn is offline Offline
Newbie Poster

Re: Syntax error in SQL update string

 
0
  #4
Jun 9th, 2009
Does the ID contain characters as well as numbers, or invalid "white space" characters such as <space>.

If not can you post the code in cluding the Cint function.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC