日期:2014-05-18  浏览次数:20766 次

c# 参数化问题? 急
string sql_filelist = "";
  SqlParameter[] cmd_filelist =new SqlParameter[1];
  if (Request.QueryString["pdid"]!=null)
  {
  sql_filelist = "select Pid,Ptitle,Pcontent,Pnum,Psize,Pprice,PDID,PDN,PXID,PXN,dpic,Ppic,Paddtime from ProductList where PDID=@PDID order by Pid desc";
  cmd_filelist={ new SqlParameter("@PDID", Request.QueryString["pdid"]) };
  }
  if (!string.IsNullOrEmpty(Request.QueryString["pxid"]))
  {
  sql_filelist = "select Pid,Ptitle,Pcontent,Pnum,Psize,Pprice,PDID,PDN,PXID,PXN,dpic,Ppic,Paddtime from ProductList where PxID=@PxID order by Pid desc";
  cmd_filelist ={ new SqlParameter("@PxID", Request.QueryString["PxID"]) };
  }
  if (!string.IsNullOrEmpty(Request.QueryString["pbid"]))
  {
  sql_filelist = "select Pid,Ptitle,Pcontent,Pnum,Psize,Pprice,PDID,PDN,PXID,PXN,dpic,Ppic,Paddtime from ProductList where PBrandID=@PbID order by Pid desc";
  cmd_filelist ={ new SqlParameter("@PbID", Request.QueryString["PbID"]) };
  }

这样写老是报:
cmd_filelist={ new SqlParameter("@PDID", Request.QueryString["pdid"]) };
这行的
无效的表达式项“{”


------解决方案--------------------
cmd_filelist={ new SqlParameter("@PDID", Convert.toInt32(Request.QueryString["pdid"])) };
------解决方案--------------------
好像数组像这样赋值“{ new SqlParameter("@PDID", Convert.toInt32(Request.QueryString["pdid"])) };”只有在数组创建的时候可以,但是一旦new了一次了就不行了,你只有改成cmd_filelist[0]=Request.QueryString["pdid"]); 

------解决方案--------------------
LIKE THIS
C# code

cmd_filelist[0]=new SqlParameter("@PDID", Request.QueryString["pdid"]);