0

在这个页面中只有这个查询

c1.cmd.CommandText = "update mechprofile set mech_status ='busy' where mech_regid ='" + alotmech + "'";

正在工作,其余查询不起作用。

public partial class customercare_alotmechanic : System.Web.UI.Page
{
    Class1 c = new Class1();
    Class1 c1 = new Class1();

    int sno;
    string license;
    string status;
    string alotmech;
    string mechregid;
    string mrg;
    protected void Page_Load(object sender, EventArgs e)
    {
            try
            {


                sno = Convert.ToInt32((Request.Form["sno"]));
                status = Request.Form["sta"];
                alotmech = Request.Form["Sel"];
                mrg = Request.Form["mechregid"];

                if (alotmech.Equals("Alloted"))
                {

                    c.con.Open();
                    c.cmd.CommandText = "update probprofile set Status = 'done' where Sno ='" + sno + "'";
                    c.cmd.ExecuteNonQuery();
                    c.con.Close();

                    c.con.Open();
                    c.cmd.CommandText = "update mechprofile set mech_status = 'free' where mech_regid ='" + mrg + "'";
                    c.cmd.ExecuteNonQuery();
                    c.con.Close();
                }
                else
                {
                    c.con.Open();
                    c.cmd.CommandText = "update probprofile set mechregid = '" + alotmech + "' where Sno ='" + sno + "'";
                    c.cmd.ExecuteNonQuery();
                    c.con.Close();

                    c1.con.Open();
                    c1.cmd.CommandText = "update mechprofile set mech_status ='busy' where mech_regid ='" + alotmech + "'";
                    c1.cmd.ExecuteNonQuery();
                    c1.con.Close();
                }




            }


            finally
            {
                string strScript = "<script>";
                strScript += "alert('ALOT MECHANIC PAGE..');";
                strScript += "window.location='problemstatus.aspx';";
                strScript += "</script>";
                Page.RegisterClientScriptBlock("strScript", strScript);

            }
    }
}

在上面的代码中,更新命令不起作用...我在页面上有一个表单,其中方法=发布和操作 se 到运行更新查询的此页面。

4

2 回答 2

0

检查您的参数值是否正确:

If your data type is Nvarhcar so you should use N before your constants data. i.e.
"... column= N'"+ value+ "'"
Or if your data type is int so don't use '. i.e.
"... column= "+ value
于 2012-09-26T10:02:52.757 回答
0

您是否测试了要添加到查询语句后缀的变量的值?例如,在使用这些值进行更新之前检查 sno、status 和 mrg 是否实际上包含有效值。如果其中任何一个为空或包含与您的表设计有关的不可接受的值,则查询将失败。

你得到的错误声明是什么?我看到你有一个尝试......最后但没有抓住。您应该始终捕获异常以促进更好的错误处理。

于 2012-09-26T10:03:01.583 回答