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

C#参数化问题
今天第一次使用参数化形式,但是值一直无法传过去,请大家指点指点
  com6.CommandText = "Select wlmc,gz,pz,gg,bz,zjm from wl where wlid like '@Wlid'; Select kfmc from kf where kfid = @Kfid_to";

  com6.Parameters.Add(new SqlParameter("@Wlid", Wlid));
  com6.Parameters.Add(new SqlParameter("@Kfid_to", Kfid_to));
为什么Wlid和Kfid_to的值有,但是@Wlid和@Kfid_to的值没有?

------解决方案--------------------
com6.Parameters.Add(new SqlParameter(@"Wlid", Wlid));
com6.Parameters.Add(new SqlParameter(@"Kfid_to", Kfid_to));
试看
------解决方案--------------------
C# code

com6.Parameters.Add(new SqlParameter("@Wlid", Wlid));
com6.Parameters.Add(new SqlParameter("@Kfid_to", Kfid_to));

com6.CommandText = "Select wlmc,gz,pz,gg,bz,zjm from wl where wlid like '@Wlid'; Select kfmc from kf where kfid = @Kfid_to";

------解决方案--------------------
两个查询语句分开写,设置参数
第一个:Select wlmc,gz,pz,gg,bz,zjm from wl where wlid like '@Wlid',这里不需要 '';

建议这样写好点:
sb.append("Select wlmc,gz,pz,gg,bz,zjm from wl ");
sb.append(" where wlid like '%' + ");
sb.append(" @Wlid ");
sb.append(" + '%' ");
------解决方案--------------------
探讨
今天第一次使用参数化形式,但是值一直无法传过去,请大家指点指点
com6.CommandText = "Select wlmc,gz,pz,gg,bz,zjm from wl where wlid like '@Wlid'; Select kfmc from kf where kfid = @Kfid_to";

com6.Parameters……

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

                        byte[] FullPic = (byte[])de.Key;
                        byte[] SmallPic = (byte[])de.Value;
                        string FullPicSql = string.Format("insert into ProductFullPic (ProductID,Content) values({0},@pic)", productID);
                        string SmallPicSql = string.Format("insert into ProductSmallPic (ProductID,Content) values({0},@pic)", productID);
                        //插入原图
                        cmd.CommandText = FullPicSql;
                        cmd.Parameters.Add("@pic", MySqlDbType.Blob);
                        cmd.Parameters["@pic"].Value = FullPic;
                        count += cmd.ExecuteNonQuery();
                        //插入缩略图
                        cmd.CommandText = SmallPicSql;
                        //cmd.Parameters.Add("@pic", MySqlDbType.Blob);
                        cmd.Parameters["@pic"].Value = SmallPic;
                        count += cmd.ExecuteNonQuery();