Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

i got an error :--
Syntax error in INSERT INTO statement

with following code:--

VB
sub Submit_Contact_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim nm = Request("textbox1")
        Dim cn = Request("textbox2")
        Dim em = Request("textbox3")
        Dim msg = Request("textbox4")

        ds=new DataSet()
        dbcomm=New OleDbCommand("Insert * INTO contact VALUES(1+'"+nm+"','"+cn+"','"+em+"','"+msg+"')",dbconn)
        dbconn.Open()
        dbcomm.ExecuteNonQuery()
        dbadp = New OleDbDataAdapter(dbcomm)
        dbconn.close()
        dbadp.fill(ds)

    end sub


please help me...!


Posted

Hi,
Insert can not be followed by '*'. Insert syntax:

SQL
INSERT INTO table_name
VALUES (value1, value2, value3,...)

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)


Cheers
 
Share this answer
 
Comments
Keyuroz 8-Apr-12 13:47pm    
but after remove * i also got an error like Syntax Error

dbcomm=New OleDbCommand("Insert INTO contact VALUES ('"+nm+"','"+cn+"','"+em+"','"+msg+"')",dbconn)
Reza Ahmadi 8-Apr-12 14:55pm    
Try to use string.Format to create your statement easier with fewer mistakes. One more thing, if it is possible try to run your query in the Db first.
I told you not to use string concatenation: I have Got an error with insert query...Help me[^].

You really should not do it. And you should not re-post the questions. Please don't.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900