为什么asp.net不会删除我的行?

tho*_*yer 2 c# asp.net

我试图从我的数据库中删除一行,

这是我的代码:

sql = "delete sum_lines from sum_lines join sum_tbl on sum_lines.summary_id = sum_tbl.id where sum_tbl.user_id = @userId and sum_lines.line_id ='@lineId'";

        SqlConnection con = new SqlConnection(conString);
        dataObj = new DataObj();
        SqlCommand com = new SqlCommand(sql, con);
        com.Parameters.Add(new SqlParameter("@userId", userId));
        com.Parameters.Add(new SqlParameter("@lineId", lineId));


        con.Open();
        com.ExecuteNonQuery();
        con.Close();
Run Code Online (Sandbox Code Playgroud)

问题是,如果我在管理工具中尝试我的sql语句,它就能完美运行.但是当我的代码运行时它不会对我的数据库产生影响.

它去了这个代码,我可以在我的调试模式中看到,但它不会因某些原因而影响.任何输入?

Igo*_*gor 6

删除单引号'@lineId'.使用引号,您@lineid在第二个条件中指定值等于string.

  • @thormayer - 将sql语句中的参数视为变量.使用`com.Parameters.Add`指定这些变量的值. (2认同)