ASP.net 查询值的数目与目标字段中的数目不同。 求解 这怎么还会有问题啊
protectedvoidButton8_Click(objectsender,EventArgse){strings;AccessDataSource1.DataFil...
protected void Button8_Click(object sender, EventArgs e)
{
string s;
AccessDataSource1.DataFile = "~/学生信息.mdb";
s = "insert into 学生信息(ID,姓名,性别,生日,成绩) values(";
s = s + "'" + TB_Number.Text + "'";
s = s + ",'" + TB_Name.Text + "'";
s = s + ",'" + TB_Sex.Text + "'";
s = s + ",'" + TB_Birthday.Text + "'";
s = s + ",'" +TB_Score.Text + "')";
Label1.Text = s;
AccessDataSource1.InsertCommand = s;
AccessDataSource1.Insert();
} 展开
{
string s;
AccessDataSource1.DataFile = "~/学生信息.mdb";
s = "insert into 学生信息(ID,姓名,性别,生日,成绩) values(";
s = s + "'" + TB_Number.Text + "'";
s = s + ",'" + TB_Name.Text + "'";
s = s + ",'" + TB_Sex.Text + "'";
s = s + ",'" + TB_Birthday.Text + "'";
s = s + ",'" +TB_Score.Text + "')";
Label1.Text = s;
AccessDataSource1.InsertCommand = s;
AccessDataSource1.Insert();
} 展开
2个回答
展开全部
这样的sql语句。
大可不必这样写
string s = @"insert into 学生信息(ID,姓名,性别,生日,成绩) values
('$TB_Number$','$TB_Name$','$TB_Sex$','$TB_Birthday$','$TB_Score$')";
string sql = s.Replace("$TB_Number$", TB_Number.Text)
.Replace("$TB_Name$", TB_Name.Text)
.Replace("$TB_Sex$", TB_Sex.Text)
.Replace("$TB_Birthday$", TB_Birthday.Text)
.Replace("$TB_Score$", TB_Score.Text);
如果ID是自动增长列就不要录入ID。直接跳过。
string s = @"insert into 学生信息(姓名,性别,生日,成绩) values
('''$TB_Name$','$TB_Sex$','$TB_Birthday$','$TB_Score$')";
string sql = s.Replace("$TB_Name$", TB_Name.Text)
.Replace("$TB_Sex$", TB_Sex.Text)
.Replace("$TB_Birthday$", TB_Birthday.Text)
.Replace("$TB_Score$", TB_Score.Text);
大可不必这样写
string s = @"insert into 学生信息(ID,姓名,性别,生日,成绩) values
('$TB_Number$','$TB_Name$','$TB_Sex$','$TB_Birthday$','$TB_Score$')";
string sql = s.Replace("$TB_Number$", TB_Number.Text)
.Replace("$TB_Name$", TB_Name.Text)
.Replace("$TB_Sex$", TB_Sex.Text)
.Replace("$TB_Birthday$", TB_Birthday.Text)
.Replace("$TB_Score$", TB_Score.Text);
如果ID是自动增长列就不要录入ID。直接跳过。
string s = @"insert into 学生信息(姓名,性别,生日,成绩) values
('''$TB_Name$','$TB_Sex$','$TB_Birthday$','$TB_Score$')";
string sql = s.Replace("$TB_Name$", TB_Name.Text)
.Replace("$TB_Sex$", TB_Sex.Text)
.Replace("$TB_Birthday$", TB_Birthday.Text)
.Replace("$TB_Score$", TB_Score.Text);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询