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

            }
    }
}

上記のコードでは、更新コマンドが機能していません... method=post を含むページにフォームがあり、アクションは更新クエリが実行されるこのページに設定されています。

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 に実際に有効な値が含まれているかどうかを確認してから、それらの値で更新を実行します。それらのいずれかが null であるか、テーブルの設計に関して許容できない値を含んでいる場合、クエリは失敗します。

あなたが得るエラーステートメントは何ですか?私はあなたが試しているように見えます...最後に、しかしキャッチはありません。エラー処理を改善するために、常に例外をキャッチする必要があります。

于 2012-09-26T10:03:01.583 に答える