错误:关键字“ OR”附近的语法不正确

时间:2018-12-01 05:07:29

标签: asp.net

嗨,我一直在努力寻找自己做错了什么,但似乎找不到,我希望您能帮助我。这是代码

受保护的void Button3_Click(对象发送者,EventArgs e)         {

            Random r = new Random();
            int num = r.Next(1,10);

            var GUsername = Session["U_Email"].ToString();
            conn.Open();
            query = "";
            query = "INSERT INTO [CartForDelivery] (OR,User_Email,Date,Date_To_Deliver,TotalPayment,P_Print) VALUES ('" + num + "','" + GUsername + "','" + DateTime.Now.ToString("MM/dd/yyyy") + "','" + DateTime.Now.AddDays(2).ToShortDateString() + "','" + lblmsg.Text + "','NP')";
            SqlCommand cmd = new SqlCommand(query, conn);
            cmd.ExecuteNonQuery();
            conn.Close();

            for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {

                Label gvr = (Label)GridView1.Rows[i].Cells[1].FindControl("lblname");

                conn.Open();
                SqlCommand ddcmd = new SqlCommand("update [B_Products] set OR = '" + num + "', Status = 'Complete', P_Print = 'NP' where User_Email = '" + GUsername + "' AND Date ='" + DateTime.Now.ToString("MM/dd/yyyy") + "' and Status = 'Pending' and Products = '" + gvr.Text + "'", conn);
                ddcmd.ExecuteNonQuery();
                conn.Close();
                update();
                //S Response.Redirect("ThanksC.aspx");

            }

    }

我检查是否是因为没有数据添加到我的OR中,但是我的随机数发生器似乎工作正常,下面是我检查它的方式 enter image description here

错误突出显示了cmd.ExecuteNonQuery();并在关键字“ OR”附近说出不正确的语法。

0 个答案:

没有答案