如何在asp.net中使用SQL查询删除多个表中的行?

时间:2017-01-25 17:41:32

标签: c# sql asp.net sql-server

我有两个表要删除数据:用户表和反馈表。

以下是我的代码(不起作用):

  string strConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    SqlConnection myConnect = new SqlConnection(strConnectionString);

    string strtext = "DELETE FROM [User] WHERE Username = @user";
    strtext += "DELETE FROM Feedback WHERE Username = @user";
    strtext += "DELETE FROM Light WHERE Username = @user";
    strtext += "DELETE FROM Temperature WHERE Username = @user";
    strtext += "DELETE FROM Airquality WHERE Username = @user";
    strtext += "DELETE FROM Bodycondition WHERE Username = @user";

    SqlCommand cmd = new SqlCommand(strtext, myConnect);

    cmd.Parameters.Add("@user", SqlDbType.VarChar);
    cmd.Parameters["@user"].Value = txtdeleteuser.Text;

    myConnect.Open();
    int result = cmd.ExecuteNonQuery();

有没有办法在asp.net中使用1个SQL查询从两个表中删除SAME数据?

0 个答案:

没有答案