Question Accessing Access database through vb code

shaji

New member
Joined
Dec 21, 2009
Messages
2
Programming Experience
1-3
Hello friends,
Recently I noticed a special problem when writing to access database from a textbox. It doesn't work if the text contains the ' character. for example if give the text as "vista" or "vistas" it will accept. If we give like
"vista's" then the following error messege will come.
System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression ''vista's','','','')'.

My code is given below

cmd = New OleDbCommand(("insert into TBL_ORDER " & "(ReceiptNr,JobNr,CustFirstName,CustLastName,CustAddress,CustPhoneRes,CustPhoneShop,CustPhoneMobile,Category,Make,ModelNr,SerialNr,OrderDate,DeliveryDate,Faults,Bill,PartsReplaced,Remarks)" & _
" values('" & .txtReceiptNr.Text & "','" & .txtJobNr.Text & "','" & .txtFirstName.Text & "','" & .txtLastName.Text & "','" & .txtAddress.Text & "','" & .txtPhoneRes.Text & "','" & .txtPhoneShop.Text & "','" & .txtMobile.Text & "','" & .cboCategory.Text & "','" & .txtMake.Text & "','" & .txtModelNr.Text & "','" & .txtSerialNr.Text & "','" & Format(OrderDatePicker.Value, "dd-MM-yyyy") & "','" & .txtDeliveryDate.Text & "','" & .txtFaults.Text & "','" & .txtBill.Text & "','" & .txtPartsReplaced.Text & "','" & .txtRemarks.Text & "')"), cn)

cn.Open()
dr = cmd.ExecuteReader()
dr.Close()
cn.Close()
MsgBox("New record saved")
End With

Please help
Thanks in advance.
Shaji.
 
Use parameters instead - see the link in my signature.
 
Back
Top