大家帮忙看看DataTable的Select 方法的问题
高手帮我看看下面的问题,
我试图在DataTable中进行Select 查询
用到了Like语句
DataRow[] drs = DataSource1.Select( "客户姓名 LIKE '% " + this.txtKHXM.Text.ToString().Trim() + "% ' ");应该是这句话的问题,但怎么也实现不了。。
大家帮忙看看哪里出了问题啊。多谢了。
下面是完整代码。
this.dgvKHZL.DataSource = null;
OleDbConnection conn = DB.conCreate();
OleDbDataAdapter oda = new OleDbDataAdapter( "Select id as 客户编号,name as 客户姓名,sex as 性别,birthday as 出生日期,address as 地址,tel as 联系电话,clienttype as 客户类别,sellbehavior as 销售行为 from clients ", conn);
DataSet ds = new DataSet();
oda.Fill(ds, "aa ");
DataTable DataSource1 = ds.Tables[ "aa "].Copy();
if (this.txtKHXM.Text.ToString().Trim() != " ")
{
DataTable dt = DataSource1.Clone();
DataRow[] drs = DataSource1.Select( "客户姓名 LIKE '% " + this.txtKHXM.Text.ToString().Trim() + "% ' ");
foreach (DataRow dr in drs)
{
dt.ImportRow(dr); //注意ImportRow和Add的区别
}
DataSource1.Clear();
DataSource1 = dt.Copy();
}
this.dgvKHZL.DataSource = DataSource1.DefaultView;
------解决方案--------------------DataRow[] drs = DataSource1.Select( "客户姓名 LIKE '% " + this.txtKHXM.Text.ToString().Trim() + "% ' ");应该是这句话的问题,但怎么也实现不了。。
---------------------
DataRow[] drs = DataSource1.Select( "name LIKE '% " + this.txtKHXM.Text.ToString().Trim() + "% ' ");