007iceman
January 25th, 2006, 04:58 AM
hi pple i have the following code to insert values into a table but it gives me a error on the line "cmdinsert.ExecuteNonQuery()" .I'm using a dropdown n sending its value,when i remove that particular filed from the insert it works jus fine
Error:
Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Source Error:
Line 44: Dim sinsert = "insert into Questionbank(Question,OptionA,OptionB,OptionC,OptionD,Key) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "'," & DropDownList1.SelectedValue & ")"
Line 45: Dim cmdinsert As New OleDb.OleDbCommand(sinsert, cnAccess)
Line 46: cmdinsert.ExecuteNonQuery()
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnAccess As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\ADO.NET\Testdb.mdb")
cnAccess.Open()
Dim sinsert = "insert into Questionbank(Question,OptionA,OptionB,OptionC,OptionD,Key) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "'," & DropDownList1.SelectedValue & ")"
Dim cmdinsert As New OleDb.OleDbCommand(sinsert, cnAccess)
cmdinsert.ExecuteNonQuery()
cnAccess.Close()
End Sub
Please help me guyz
Error:
Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Source Error:
Line 44: Dim sinsert = "insert into Questionbank(Question,OptionA,OptionB,OptionC,OptionD,Key) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "'," & DropDownList1.SelectedValue & ")"
Line 45: Dim cmdinsert As New OleDb.OleDbCommand(sinsert, cnAccess)
Line 46: cmdinsert.ExecuteNonQuery()
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnAccess As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\ADO.NET\Testdb.mdb")
cnAccess.Open()
Dim sinsert = "insert into Questionbank(Question,OptionA,OptionB,OptionC,OptionD,Key) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "'," & DropDownList1.SelectedValue & ")"
Dim cmdinsert As New OleDb.OleDbCommand(sinsert, cnAccess)
cmdinsert.ExecuteNonQuery()
cnAccess.Close()
End Sub
Please help me guyz