To troubleshoot the problem, Try the following steps:
1. CHECK if you have a complete SQL command on the query your trying to submit.
SELECT [fields] FROM [table] WHERE [expression]
INSERT INTO [table] ([field1],...) VALUES ([value1],...) WHERE [expression]
UPDATE [table] SET [field1]=[value1] WHERE [expression]
2. CHECK for extra qoutes inside the string value your trying to pass.
For example:
INSERT INTO tblCustomer(firstname,lastname) VALUES('Fryan's','Digital World')
This query will give you the "Syntax error (missing operator) in query expression" error due to the extra qoute in the second string value: 'Fryan's'
You can avoid this in .NET, by using the Replace() function before you pass the string value to complete the query as shown below.
Dim strQuery as String
Dim strFirstname as String = "Fryans's"
Dim strLastname as String = "Digital World"
strQuery = "INSERT INTO tblCustomer(firstname,lastname) VALUES('" & strFirstname.ToString.Replace("'", "") & "','" & strLastname.ToString.Replace("'", "") & "')"
** C# has the same syntax of Replace function
Remember that its the responsibility of the programmer to prevent this type of errors. We should not blame our users if they trying to input extra quotes during data entries.
For more .NET tips and tricks, subscribe now
1 comments:
That makes no sense, you need to replace ' with '' access will add it to the db with 1 ' like it should be.
Post a Comment