INSERT 语句中列的数目大于 VALUES 子句中指定的值的数目。VALUES 子句中值的数目必须与 INSERT 语句中指定的列的数目匹配。
SqlConnection conn = BaseClass.DBConn.CyCon();
conn.Open();
SqlCommand cmd = new SqlCommand("insert into Hire(HireID,FilmID,Amount,HireDate,EmployeeID,DueDate,Rent,Discount,CustomerID) values('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox6.Text.Trim() + "','" + textBox7.Text.Trim() + "','" + textBox8.Text.Trim() + "','" + textBox9.Text.Trim() + "')", conn);;
cmd.ExecuteNonQuery();
conn.Close();
GetData();
------解决方案--------------------
你的:
insert into Hire(HireID,FilmID,Amount,HireDate,EmployeeID,DueDate,Rent,Discount,CustomerID) 有9个列,
但是你的values('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox6.Text.Trim() + "','" + textBox7.Text.Trim() + "','" + textBox8.Text.Trim() + "','" + textBox9.Text.Trim() + "')" 只有7个列,
所以你还得在values再加上2列。
------解决方案--------------------
或者就把
insert into Hire(HireID,FilmID,Amount,HireDate,EmployeeID,DueDate,Rent,Discount,CustomerID) 中去掉两列也可以,看你的业务需求。
------解决方案--------------------
values那里少了列,或者和insert中的表列数量不对应