错误附近有语法错误使用C#

问题描述:

这种说法提供了以下错误:错误附近有语法错误使用C#

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Incorrect syntax near ','.

注:我的表有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(); 
+1

那么你插入23场所以这不是一个良好的开端 –

+0

如果你不插入所有的值,你需要指定的查询,而不是添加逗号(据我所知)。该查询无效。 –

如果你的表有23列和你不想插入所有23列,然后在Insert中提及所需列列表。无需添加逗号

Insert into tbl_tarifmoshtari 
(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16) 
values 
(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10,@p11,@p12,@p13,@p14,@p15,@p16) 
+0

谢谢我亲爱的朋友 –

+0

我帮了你很大的忙 我希望你永远健康快乐 我接受你作为另一个国家的朋友! –