ASP.NET+SQL 模糊查询查不到值,希望有人指点下
存储过程ALTERPROCEDURESupplie_Reduce_Sel(@hcbhchar(4),@hcnamenvarchar(50),@bmidchar(2))AS...
存储过程
ALTER PROCEDURE Supplie_Reduce_Sel
(
@hcbh char(4) ,
@hcname nvarchar(50),
@bmid char(2)
)
AS
select hcbh,hcname,hcgg,bz from hcbm where
hcbh like @hcbh and
hcname like @hcname and
bmid like @bmid and
hcbh in (select hcbh from hcxx where hcsl>0)
RETURN
执行函数:
public DataTable ReturnTable_Info(hcbm bm)
{
SqlParameter[] parmas ={new SqlParameter("@hcbh",SqlDbType.Char,4) ,
new SqlParameter("@hcname",SqlDbType.NVarChar,50) ,
new SqlParameter("@bmid",SqlDbType.Char,2)
};
parmas[0].Value = "%"+bm.hcbh+"%";
parmas[1].Value = "%"+bm.hcname+"%";
parmas[2].Value = "%"+bm.bmid+"%";
DataTable dt = db.ExecuteProcTable("Supplie_Reduce_Sel",parmas);
db.CloseDatabase();
return dt;
}
网页代码:
bm.hcbh = this.Txt_Sup_Id.Value.ToString();
bm.hcname = this.Txt_Sup_Name.Value.ToString();
bm.bmid = this.Ddl_Sup_Dep.SelectedValue.ToString();
DataTable dt = src.ReturnTable_Info(bm);
this.Gv_Sup_Rec_Info.DataSource = dt;
this.Gv_Sup_Rec_Info.DataKeyNames = new string[] { "hcbh" };
this.Gv_Sup_Rec_Info.DataBind(); 展开
ALTER PROCEDURE Supplie_Reduce_Sel
(
@hcbh char(4) ,
@hcname nvarchar(50),
@bmid char(2)
)
AS
select hcbh,hcname,hcgg,bz from hcbm where
hcbh like @hcbh and
hcname like @hcname and
bmid like @bmid and
hcbh in (select hcbh from hcxx where hcsl>0)
RETURN
执行函数:
public DataTable ReturnTable_Info(hcbm bm)
{
SqlParameter[] parmas ={new SqlParameter("@hcbh",SqlDbType.Char,4) ,
new SqlParameter("@hcname",SqlDbType.NVarChar,50) ,
new SqlParameter("@bmid",SqlDbType.Char,2)
};
parmas[0].Value = "%"+bm.hcbh+"%";
parmas[1].Value = "%"+bm.hcname+"%";
parmas[2].Value = "%"+bm.bmid+"%";
DataTable dt = db.ExecuteProcTable("Supplie_Reduce_Sel",parmas);
db.CloseDatabase();
return dt;
}
网页代码:
bm.hcbh = this.Txt_Sup_Id.Value.ToString();
bm.hcname = this.Txt_Sup_Name.Value.ToString();
bm.bmid = this.Ddl_Sup_Dep.SelectedValue.ToString();
DataTable dt = src.ReturnTable_Info(bm);
this.Gv_Sup_Rec_Info.DataSource = dt;
this.Gv_Sup_Rec_Info.DataKeyNames = new string[] { "hcbh" };
this.Gv_Sup_Rec_Info.DataBind(); 展开
2个回答
展开全部
%当成是值啦,应该这样改:
存储过程
ALTER PROCEDURE Supplie_Reduce_Sel
(
@hcbh char(4) ,
@hcname nvarchar(50),
@bmid char(2)
)
AS
select hcbh,hcname,hcgg,bz from hcbm where
hcbh like '%'+@hcbh+'%' and
hcname like '%'+@hcname+'%' and
bmid like '%'+@bmid +'%' and
hcbh in (select hcbh from hcxx where hcsl>0)
RETURN
执行函数:
public DataTable ReturnTable_Info(hcbm bm)
{
SqlParameter[] parmas ={new SqlParameter("@hcbh",SqlDbType.Char,4) ,
new SqlParameter("@hcname",SqlDbType.NVarChar,50) ,
new SqlParameter("@bmid",SqlDbType.Char,2)
};
parmas[0].Value =bm.hcbh;
parmas[1].Value =bm.hcname;
parmas[2].Value =bm.bmid;
DataTable dt = db.ExecuteProcTable("Supplie_Reduce_Sel",parmas);
db.CloseDatabase();
return dt;
}
存储过程
ALTER PROCEDURE Supplie_Reduce_Sel
(
@hcbh char(4) ,
@hcname nvarchar(50),
@bmid char(2)
)
AS
select hcbh,hcname,hcgg,bz from hcbm where
hcbh like '%'+@hcbh+'%' and
hcname like '%'+@hcname+'%' and
bmid like '%'+@bmid +'%' and
hcbh in (select hcbh from hcxx where hcsl>0)
RETURN
执行函数:
public DataTable ReturnTable_Info(hcbm bm)
{
SqlParameter[] parmas ={new SqlParameter("@hcbh",SqlDbType.Char,4) ,
new SqlParameter("@hcname",SqlDbType.NVarChar,50) ,
new SqlParameter("@bmid",SqlDbType.Char,2)
};
parmas[0].Value =bm.hcbh;
parmas[1].Value =bm.hcname;
parmas[2].Value =bm.bmid;
DataTable dt = db.ExecuteProcTable("Supplie_Reduce_Sel",parmas);
db.CloseDatabase();
return dt;
}
追问
你说的我也试过,模糊查询文本加上2个%长度必须要和查询字段的字符长度相同才查得到数据
追答
不会吧,如果字段 hcbh的值为‘abcd',那‘%’+@hcbh+’%' (@hcbh='bc') 就可以搜到了吧··
长度要一样,没试过这种情况····
将下面的改成下面的试下
SqlParameter[] parmas ={new SqlParameter("@hcbh",SqlDbType.Char) ,
new SqlParameter("@hcname",SqlDbType.NVarChar) ,
new SqlParameter("@bmid",SqlDbType.Char)
};
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询