C#+Access查询值的数目与目标字段中的数目不同
OleDbCommandcmd2=newOleDbCommand();cn1.Open();stringsql,sql1,sql2;sql1="INSERTINTOStu...
OleDbCommand cmd2 = new OleDbCommand();
cn1.Open();
string sql, sql1, sql2;
sql1 = "INSERT INTO StudentInfo (StuID,StuName,Sex,Race,Address,Tel,EntranceYear,ClassID,Academy,Specialty,Role,Postal";
sql2 = " VALUES ('" + idbox.Text.ToString() + "','" + namebox.Text.ToString() + "','" + sexbox.Text.Trim() + "','" + racebox.Text.ToString() + "','" + addressbox.Text.ToString() + "','" + telbox.Text.ToString() + "','" + yearbox.Text.Trim() + "','" + banjibox.Text.Trim() + "','" + xueyuanbox.Text.Trim() + "','" + zhuanyebox.Text.Trim() + "','" + rolebox.Text.ToString() + "','" + postalbox.Text.ToString() + "'";
cmd2.Connection = cn1;
sql = sql1 + ")" + sql2 + ")";
cmd2.CommandText = sql;
cmd2.ExecuteNonQuery();
cn1.Close();
MessageBox.Show("学生信息添加成功");
我的Access数据库为 展开
cn1.Open();
string sql, sql1, sql2;
sql1 = "INSERT INTO StudentInfo (StuID,StuName,Sex,Race,Address,Tel,EntranceYear,ClassID,Academy,Specialty,Role,Postal";
sql2 = " VALUES ('" + idbox.Text.ToString() + "','" + namebox.Text.ToString() + "','" + sexbox.Text.Trim() + "','" + racebox.Text.ToString() + "','" + addressbox.Text.ToString() + "','" + telbox.Text.ToString() + "','" + yearbox.Text.Trim() + "','" + banjibox.Text.Trim() + "','" + xueyuanbox.Text.Trim() + "','" + zhuanyebox.Text.Trim() + "','" + rolebox.Text.ToString() + "','" + postalbox.Text.ToString() + "'";
cmd2.Connection = cn1;
sql = sql1 + ")" + sql2 + ")";
cmd2.CommandText = sql;
cmd2.ExecuteNonQuery();
cn1.Close();
MessageBox.Show("学生信息添加成功");
我的Access数据库为 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |