日期:2014-05-17 浏览次数:20448 次
//1 单纯的sql语句 string str = "select * from Testtable where '地区字段' like '%" + TextBox1.Text+ "%'"; // 2 查询方法 public DataTable AllEvent_Select(string dq) { try { string str = "select * from Testtable where '地区字段' like '%" + dq+ "%'"; cmd = SqlHelper.CreateDbCommand(str, conn); conn.Open(); DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader()); return dt; }
------解决方案--------------------
//上面方法少代码,这是全的 public DataTable AllEvent_Select(string dq) { try { string str = "select * from Testtable where '地区字段' like '%" + dq+ "%'"; cmd = SqlHelper.CreateDbCommand(str, conn); conn.Open(); DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader()); return dt; } catch (Exception e) { throw e; } finally { conn.Close(); } }