syntax error while inserting data into ms access table

前端 未结 3 792
孤街浪徒
孤街浪徒 2021-01-28 23:31

I have a following code:

OleDbConnection aConnection = new
                    OleDbConnection(\"Provider=Microsoft.ACE.OLEDB.12.0;
                                     


        
3条回答
  •  面向向阳花
    2021-01-29 00:30

    Your insert syntax is incorrect... you need to () around both the fields you are inserting AND the values clause...

    insert into Client
       ( cname, phone, [password] )
       values
       ( ?, ?, ? )
    

    The "?" are place-holders for the parameters and the parameter statements must be in the same order as the "?" represent. Also, note... if the values are expected to be numeric, date, etc, make sure the values you are setting in the parameter are the correct data type too. But in your case, these are all string-based.

    OleDbCommand insert = new OleDbCommand(sql, aConnection);
    insert.Parameters.Add( "parmName", textBox1.Text );
    insert.Parameters.Add( "parmPhone", textBox2.Text );
    insert.Parameters.Add( "parmPwd", textBox3.Text );
    

提交回复
热议问题