【发布时间】:2016-11-15 16:52:35
【问题描述】:
此语句给出以下错误:
System.Data.dll 中出现“System.Data.SqlClient.SqlException”类型的未处理异常 附加信息:',' 附近的语法不正确。
注意:我的表有 22 个字段 感谢您的帮助
con.ConnectionString = @"Data Source =.\MYSQL; Initial Catalog = db_info; Integrated Security = True";
con.Open();
/SqlCommand com = new SqlCommand("insert into tbl_tarifmoshtari values(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10,@p11,@p12,@p13,@p14,@p15,@p16,,,,,,,)", con);
SqlCommand com1 = new SqlCommand();
com1.Parameters.AddWithValue("@p1", Convert.ToInt32(txbox_shomaremoshtari.Text));
com1.Parameters.AddWithValue("@p2", cmbo_jensiyat.Text);
com1.Parameters.AddWithValue("@p3", txbox_nam.Text);
com1.Parameters.AddWithValue("@p4", txbox_famil.Text);
com1.Parameters.AddWithValue("@p5", txbox_pedar.Text);
com1.Parameters.AddWithValue("@p6", txbox_tarikhtavalod.Text);
com1.Parameters.AddWithValue("@p7", txbox_shomareshenasname.Text);
com1.Parameters.AddWithValue("@p8", txbox_codmeli.Text);
com1.Parameters.AddWithValue("@p9", txbox_mahaltavalod.Text);
com1.Parameters.AddWithValue("@p10", txbox_serishenasname.Text);
com1.Parameters.AddWithValue("@p11", txbox_serialshenasname.Text);
com1.Parameters.AddWithValue("@p12", txbox_adresmanzel.Text);
com1.Parameters.AddWithValue("@p13", txbox_codpostimanzel.Text);
com1.Parameters.AddWithValue("@p14", Convert.ToInt32(txbox_telephonmanzel.Text));
com1.Parameters.AddWithValue("@p15", Convert.ToInt32(txbox_mobil.Text));
com1.Parameters.AddWithValue("@p16", txbox_email.Text);
com1.ExecuteNonQuery();
【问题讨论】:
-
你要插入 23 个字段,所以这不是一个好的开始
-
如果您没有插入所有值,则需要在查询中指定而不是添加逗号(据我所知)。该查询无效。
标签: c# sql syntax sqlcommand executenonquery