无法检测语法错误 [英] Unable to detect syntax error
本文介绍了无法检测语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SqlConnection con = new SqlConnection(@"data source=.\SQLEXPRESS;database= Registration; trusted_connection=yes ");
SqlDataAdapter sd = new SqlDataAdapter();
public Form1()
{
InitializeComponent();
}
private void btnADD_Click(object sender, EventArgs e)
{
sd.InsertCommand = new SqlCommand("insert into DBtest VALUE(@firstname, @lastname, @mobile, @emailid)", con);
sd.InsertCommand.Parameters.Add("@firstname", SqlDbType.VarChar).Value = tbfname.Text;
sd.InsertCommand.Parameters.Add("@lastname", SqlDbType.VarChar).Value = tblname.Text;
sd.InsertCommand.Parameters.Add("@mobile", SqlDbType.Int).Value =Convert.ToInt32(tbmobile.Text);
sd.InsertCommand.Parameters.Add("@emailid", SqlDbType.VarChar).Value = tbemail.Text;
con.Open();
sd.InsertCommand.ExecuteNonQuery();
con.Close();
}
}
它显示"VALUE附近的语法不正确".在"sd.InsertCommand.ExecuteNonQuery();"
It showing "Incorrect syntax near ''VALUE''." at "sd.InsertCommand.ExecuteNonQuery();"
推荐答案
值不等于值:
It''s VALUES not VALUE:
sd.InsertCommand = new SqlCommand("insert into DBtest VALUE(@firstname, @lastname, @mobile, @emailid)", con);
成为
sd.InsertCommand = new SqlCommand("insert into DBtest VALUES(@firstname, @lastname, @mobile, @emailid)", con);
但是,最好命名它们将要进入的字段-这样以后进行数据库更改不会使您的程序搞砸!
However, it is a good idea to name the fields they are going to go into - that way a later database change does not screw your program up!
INSERT INTO Videos (Id, ImageFront, ImageBack, ImageCombined, Title) VALUES (@ID, @CF, @CR, @CB, @TI)
看看查询之间的区别:
Take a look at the differences between quesries:
insert into DBtest VALUE(@firstname, @lastname, @mobile, @emailid)
正确的是:
Correct one is:
insert into DBtest (Column1, Column2, Column3, Column4)
VALUES(@firstname, @lastname, @mobile, @emailid)
这篇关于无法检测语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文