protected void But_ok_Click(object sender, EventArgs e)
    {
        string list = Request.Form["chk_list"];  //chk_list 是一组checkbox的值
        string checkdata = tex_checkDate.Text.Trim();
        if (list != "" && checkdata !="")
       {
           SqlConnection con = new SqlConnection(conString);
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = con;
           cmd.CommandText = "update GGPRODUCT set isChecked=1, checkedName='改名字', checkedDate=@checkedDate where ID in (" + list + ")";
           cmd.Parameters.AddWithValue("@checkedDate", Convert.ToDateTime(checkdata));
           using (con)
           {
               con.Open();
               int queryResult = cmd.ExecuteNonQuery(); //当list =""的时候编译器提示错误(')' 附近有语法错误。) 但是当list !=""的时候语句可以执行
               if (queryResult != 0)
               {
                   Response.Write("<script language=javascript>alert('验收成功');location.href='productMakeList.aspx'; </script>");
               }
               else
               {
                   Response.Write("<script language=javascript>alert('操作失败'); </script>");
               }
           }
       }
       else
       {
           Response.Write("<script language=javascript>alert('请先选择和输入时间'); </script>");
       }
    }

解决方案 »

  1.   

    if (!string.IsNullOrEmpty(list) && !string.IsNullOrEmpty(checkdata))
    {}
      

  2.   

    cmd.CommandText = "update GGPRODUCT set isChecked=1, checkedName='改名字', checkedDate=@checkedDate where ID in (" + list + ")";
    有问题
      

  3.   

     if (list != "" && checkdata !="")
    改为
     if (list != "" && list !=null && checkdata !="" && checkdata!=null )
      

  4.   

    IsNullOrEmptyNULL !=  string.Empty。