日期:2014-05-18  浏览次数:20932 次

C#中怎么同时像两个表中插入数据啊?附上我的代码
string s= @"Data Source=.\SQLEXPRESS;Initial Catalog=学生管理系统;Integrated Security=True";
  string sq = "Insert Into Student(StudentName,StudentNum,StudentSex,StudentAge,StudentSdept) Values('"; sq += textBox1.Text + "' , '"; sq += textBox2.Text + "' , '"; sq += textBox3.Text + "','"; sq += textBox4.Text + "','"; sq += textBox5.Text + "') , Insert Into Accommodation(DorID) Values('"; sq += textBox6.Text + "')";

  SqlConnection conn=new SqlConnection(s);

  conn.Open();

  SqlCommand da=new SqlCommand(sq, conn);

  da.ExecuteNonQuery(); //执行SQL语句

  conn.Close(); //关闭数据库连接

------解决方案--------------------
Insert Into Accommodation 把这句前面的逗号换成分号