我想在SQL表中保存新记录。 这个表字段之一是我想通过使用会话添加记录的“用户名”,而其他字段是从用户获取的。 这是我在C#asp.net代码:INSERT语句中的列数多于VALUES子句中指定的值。 VALUES claus中值的个数
protected void savesubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=Khayati;Integrated Security=True");
string qu = string.Format("insert into Ordertb (nokar,modeledokht,tozihat,username) values('{0}','{1}',N'{2}',N'{3}')", DropDownList1.Text, DropDownList2.Text, tozihtxt.Text, Convert.ToString(Session["username1"]));
SqlDataAdapter da = new SqlDataAdapter(qu, con);
DataSet ds = new DataSet();
da.Fill(ds, "ordertbl");
}
但是当我运行它,我看到这个错误:
There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
Description: An unhandled exception occurred during the execution of the current web request. please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
应该可能是“{0}”,“{1}”,“N”,“{2}”。注意''' – VDWWD