【发布时间】:2018-10-02 07:32:11
【问题描述】:
我正在尝试将文本框中的值添加到 datagridview 中,我之前曾问过这个问题,但我现在遇到了一个不同的错误说
INSERT 语句中的列多于 VALUES 子句中指定的值。 VALUES 子句中的值数必须与 INSERT 语句中指定的列数匹配。
这是导致错误的代码
private void SaveBtn_Click(object sender, EventArgs e)
{
SqlConnection sc = new SqlConnection();
SqlCommand com = new SqlCommand();
sc.ConnectionString = ("Data Source=localhost;Initial Catalog=LoginScreen;Integrated Security=True");
sc.Open();
com.Connection = sc;
com.CommandText = ("INSERT INTO Stock (Prod_ID, Prod_Name, Prod_Cat, Supplier, Cost, Price_1, Price_2, Price_3) VALUES ('"+ProdID.Text+"''"+ProdName.Text+"'+'"+ProdCat.Text+"'+'"+ProdSup.Text+"'+'"+ProdCost.Text+"'+'"+ProdPrice1.Text+"'+'"+ProdPrice2.Text+"'+'"+ProdPrice3.Text+"');");
com.ExecuteNonQuery();
sc.Close();
}
【问题讨论】:
-
值数据字段之间没有逗号,也请参数化! stackoverflow.com/questions/11905185/…
标签: c# sql sql-server winforms