insert语句中的列数少于VALUES子句中指定的值。 [英] There are fewer columns in the insert statement than values specified in the VALUES clause.
本文介绍了insert语句中的列数少于VALUES子句中指定的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
con = new SqlConnection(cs.Con);
con.Open();
string CB = "Insert into CustomerDetails(Married,FirstName,LastName,Gender,Occupation,Zone,District,VDC,MobileI,MobileII,Email,URL,NoOfAdults,Relation,RoomType,NoOfRoom,Notes)VALUES(@d1,@d2,@d3,'"+gender+"',@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18)";
cmd = new SqlCommand(CB);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@d1", checkBox1.Text);
cmd.Parameters.AddWithValue("@d2", txtFirstName.Text);
cmd.Parameters.AddWithValue("@d3", txtLastName.Text);
cmd.Parameters.AddWithValue("@d5", cmbOccopation.Text);
cmd.Parameters.AddWithValue("@d6", cmbZone.Text);
cmd.Parameters.AddWithValue("@d7", cmbDistrict.Text);
cmd.Parameters.AddWithValue("@d8", cmbVDC.Text);
cmd.Parameters.AddWithValue("@d9", txtMobileI.Text);
cmd.Parameters.AddWithValue("@d10", txtMobileII.Text);
cmd.Parameters.AddWithValue("@d11", txtEmail.Text);
cmd.Parameters.AddWithValue("@d12", txtURL.Text);
cmd.Parameters.AddWithValue("@d13", txtNoFAdults.Text);
cmd.Parameters.AddWithValue("@d14", cmbRelation.Text);
cmd.Parameters.AddWithValue("@d15", txtChildren.Text);
cmd.Parameters.AddWithValue("@d16", cmbRoomType.Text);
cmd.Parameters.AddWithValue("@d17", txtNoFRooms.Text);
cmd.Parameters.AddWithValue("@d18", txtNotes.Text);
cmd.ExecuteReader();
con.Close();
MessageBox.Show("Data Saved successfully", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
ClearData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
我的尝试:
插入语句中的列少于VALUES子句中指定的值。
What I have tried:
There are fewer columns in the Insert Statement than values specified in the VALUES clause.
推荐答案
嗯,是的。有。
Well, yes. There are.
string CB = "Insert into CustomerDetails(Married,FirstName,LastName,Gender,Occupation,Zone,District,VDC,MobileI,MobileII,Email,URL,NoOfAdults,Relation,RoomType,NoOfRoom,Notes)VALUES(@d1,@d2,@d3,'"+gender+"',@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18)";
列名为:17
提供的值:18。
检查并添加另一个列名,或检查并删除一个值...我怀疑你错过了Children列。
Columns named: 17.
Values supplied: 18.
Either check and add another column name, or check and remove a value...I suspect you are missing the Children column.
cmd.Parameters.AddWithValue("@d15", txtChildren.Text);
没有专栏有关 Children
的参数。这就是你的不同之处。
建议:避免在SQL查询中连接用户填充的字符串,它打开了SQL注入的大门。
There is no column for the parameter about Children
. That is where is your difference.
Advice: avoid concatenating a string filled by user in an SQL query, it open the door to SQL injection.
这篇关于insert语句中的列数少于VALUES子句中指定的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文