Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新查询不工作C#asp.net_C#_Asp.net_Sql Server_Sql Update - Fatal编程技术网

更新查询不工作C#asp.net

更新查询不工作C#asp.net,c#,asp.net,sql-server,sql-update,C#,Asp.net,Sql Server,Sql Update,在此页面中,仅此查询 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 C

在此页面中,仅此查询

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);

            }
    }
}
public部分类customercare\u alotmechanic:System.Web.UI.Page
{
Class1 c=新的Class1();
Class1 c1=新的Class1();
int-sno;
字符串许可证;
字符串状态;
弦乐高技术;
字符串机械寄存器;
字符串mrg;
受保护的无效页面加载(对象发送方、事件参数e)
{
尝试
{
sno=Convert.ToInt32((Request.Form[“sno”]);
状态=请求。表格[“sta”];
alotmech=Request.Form[“Sel”];
mrg=请求。表格[“mechregid”];
如果(alotmech.等于(“分配”))
{
c、 con.Open();
c、 cmd.CommandText=“更新probprofile集状态='done',其中Sno='“+Sno+”;
c、 cmd.ExecuteNonQuery();
c、 con.Close();
c、 con.Open();
c、 cmd.CommandText=“更新机械配置文件集机械状态='自由',其中机械注册表='”+mrg+“'”;
c、 cmd.ExecuteNonQuery();
c、 con.Close();
}
其他的
{
c、 con.Open();
c、 cmd.CommandText=“update probprofile set mechregid=”+alotmech+”,其中Sno=”+Sno+“”;
c、 cmd.ExecuteNonQuery();
c、 con.Close();
c1.con.Open();
c1.cmd.CommandText=“更新机械配置文件设置机械状态='busy',其中机械注册表='”+alotmech+”;
c1.cmd.ExecuteNonQuery();
c1.con.Close();
}
}
最后
{
字符串strScript=“”;
strScript+=“警报('ALOT mechanical PAGE..);”;
strScript+=“window.location='problemstatus.aspx';”;
strScript+=“”;
第页:RegisterClientScriptBlock(“strScript”,strScript);
}
}
}

在上面的代码中,更新命令不起作用。。。我在一个页面上有一个表单,其中method=post,action se指向运行更新查询的页面。

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

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

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


你得到的错误陈述是什么?我看到你试了一次…最后还是没成功。您应该始终捕获异常以促进更好的错误处理

这些命令怎么不起作用?你收到错误了吗?如果是,错误是什么?或者您正在查看数据库,发现
更新
没有任何效果?此外-以您正在执行的方式构建SQL字符串是一个坏主意-您最好使用+1作为@ElRonnoco关于参数化查询的注释。请大家注意,每次你们这样连接sql,都会有一只小猫死:-)谢谢你们的建议。。。值没有按我所希望的那样传递。。。。我肯定会添加一个“catch”命令来捕获发生的任何错误,这样您就可以看到错误,并根据错误内容采取一些措施。谢谢您的建议。。。值没有按我所希望的那样传递。。。。会有所改善的