Answered by:
Syntax error (missing operator) in query expression 'sai',sss''.

Question
-
User1046783394 posted
hi,
i am new to asp.net i am trying to develop an asp.net application i,e registration form in asp.net as user interface and ms access 2007 database as backend.i am trying to make aconnection to ms access 2007 db and save the data entered by the user in asp.net application.
i have saved my access db 2007 file in 'D drive' and my code in application is:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\example\access.accdb;Persist Security Info=False; User Id=;Password=;")
Dim cmd As New OleDbCommand
With cmd
.CommandText = "insert into Table1([name_of_dealer],[dealer_id],[address],[mobile_no]) values(" & Me.TextBox1.Text & _
"'," & Me.TextBox2.Text & "'," & Me.TextBox3.Text & "'," & Me.TextBox4.Text & ")"
.Connection = cn
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
.Dispose()
End With
cn.Dispose()
End Sub
End Classi am facing error saying
Syntax error (missing operator) in query expression 'sai',sss''. so please kindly help me regarding this.
<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
Thursday, April 15, 2010 8:02 AM
Answers
-
User-1460196090 posted
Can you try this:
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\example\access.accdb;Persist Security Info=False; User Id=;Password=;")
Dim cmd As New OleDbCommand
With cmd
.CommandText = "insert into Table1([name_of_dealer],[dealer_id],[address],[mobile_no]) values('" & Me.TextBox1.Text & _
"','" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "')"
.Connection = cn
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
.Dispose()
End With
cn.Dispose()As I have noticed, you have forgotten all ' at the beginning of each '" & Me.TextBox.Text & "', ... etc
Also, if you still get this error, you probably have some '-s inside your textBox values. You will need to replace them with two '' single-quotes, like:
before adding: Me.TextBox1.Text = Me.TextBox1.Text.Replace("'","''")
Hope this helps,
Hajan
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 15, 2010 8:25 AM -
User-1360095595 posted
Use parameterized queries.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 15, 2010 8:40 AM -
User-1199946673 posted
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 15, 2010 11:42 AM
All replies
-
User-1460196090 posted
Can you try this:
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\example\access.accdb;Persist Security Info=False; User Id=;Password=;")
Dim cmd As New OleDbCommand
With cmd
.CommandText = "insert into Table1([name_of_dealer],[dealer_id],[address],[mobile_no]) values('" & Me.TextBox1.Text & _
"','" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "')"
.Connection = cn
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
.Dispose()
End With
cn.Dispose()As I have noticed, you have forgotten all ' at the beginning of each '" & Me.TextBox.Text & "', ... etc
Also, if you still get this error, you probably have some '-s inside your textBox values. You will need to replace them with two '' single-quotes, like:
before adding: Me.TextBox1.Text = Me.TextBox1.Text.Replace("'","''")
Hope this helps,
Hajan
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 15, 2010 8:25 AM -
User-1360095595 posted
Use parameterized queries.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 15, 2010 8:40 AM -
User-1199946673 posted
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 15, 2010 11:42 AM