SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ConnectionString);
SqlCommand cmd;
cmd = new SqlCommand("insert into student (name,email,mobile,userid,pass) values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"')", con);
cmd = new SqlCommand("insert into course (stid) select top (1) stid from student order by stid desc", con);
cmd = new SqlCommand("update course set coursename ='"+comboBox1.Text+"'where stid = top (1) stid from course order by stid desc",con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
我試圖使用與主鍵和外鍵關係STID單一形式兩個表中插入數據插入數據表的學生和外鍵主鍵當然連接屬性未初始化。我試圖以兩種表
希望您瞭解SQL注入。 –
你知道你正在創建的前兩個SqlCommand沒有被使用,對吧? –
您的第一個兩個命令不會執行。只有第三個命令會執行,因爲您將兩次替換命令cmd。 –