c#模糊查询数据库,SQL语句在数据库中可以运行,在控件中却不好用为什么?
UI层:DataSetds=lcbll.FindcontrectByConditions(textBox1.Text,textBox2.Text);dataGridVie...
UI层:DataSet ds = lcbll.FindcontrectByConditions(textBox1.Text, textBox2.Text);
dataGridView1.DataSource =ds.Tables[0];
BLL层:DataSet ds = LaborContractDal.FindByCondication(p, p_2);
return ds;
IDAL层: DataSet FindByCondication(string name, string number);
DAL层:public DataSet FindByCondication(string name, string number)
{List<SqlParameter> paramList = new List<SqlParameter>();
if (!string.IsNullOrWhiteSpace(name))
{sqlText += " and d.name like 'name'";
paramList.Add(new SqlParameter("@name", string.Format("%{0}%", name))); }
if (!string.IsNullOrWhiteSpace(number))
{sqlText += " and d.code like 'number'";
paramList.Add(new SqlParameter("@numbe", string.Format("%{0}%", number)));}
DataSet ds = ExecuteQuery(sqlText, paramList.ToArray());
return ds; 展开
dataGridView1.DataSource =ds.Tables[0];
BLL层:DataSet ds = LaborContractDal.FindByCondication(p, p_2);
return ds;
IDAL层: DataSet FindByCondication(string name, string number);
DAL层:public DataSet FindByCondication(string name, string number)
{List<SqlParameter> paramList = new List<SqlParameter>();
if (!string.IsNullOrWhiteSpace(name))
{sqlText += " and d.name like 'name'";
paramList.Add(new SqlParameter("@name", string.Format("%{0}%", name))); }
if (!string.IsNullOrWhiteSpace(number))
{sqlText += " and d.code like 'number'";
paramList.Add(new SqlParameter("@numbe", string.Format("%{0}%", number)));}
DataSet ds = ExecuteQuery(sqlText, paramList.ToArray());
return ds; 展开
3个回答
展开全部
一定是传参数出了问题,个人建议,你既然采用了3层架构模式,那么你为何不使用SQL自带的存储过程呢?这样不仅【@xxx】参数和【xxx】参数不会搞混,传参数也方便,同时,在SQL里面写代码的难度一定比在程序中低,安全性也好,何乐而不为呢? ^ ^
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DAL层:public DataSet FindByCondication(string name, string number)
{List<SqlParameter> paramList = new List<SqlParameter>();
if (!string.IsNullOrWhiteSpace(name))
{sqlText += " and d.name like 'name'";//这里改成and d.name like @name
paramList.Add(new SqlParameter("@name", string.Format("%{0}%", name))); }
if (!string.IsNullOrWhiteSpace(number))
{sqlText += " and d.code like 'number'";//这里改成and d.code like @number
paramList.Add(new SqlParameter("@numbe", string.Format("%{0}%", number)));}
DataSet ds = ExecuteQuery(sqlText, paramList.ToArray());
return ds;
{List<SqlParameter> paramList = new List<SqlParameter>();
if (!string.IsNullOrWhiteSpace(name))
{sqlText += " and d.name like 'name'";//这里改成and d.name like @name
paramList.Add(new SqlParameter("@name", string.Format("%{0}%", name))); }
if (!string.IsNullOrWhiteSpace(number))
{sqlText += " and d.code like 'number'";//这里改成and d.code like @number
paramList.Add(new SqlParameter("@numbe", string.Format("%{0}%", number)));}
DataSet ds = ExecuteQuery(sqlText, paramList.ToArray());
return ds;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
亲, dataGridView1.DataBind() 呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询