日期:2014-05-18 浏览次数:20421 次
public static List<NewsClass> GetAllNewsClass() { string sql = "select * from NewsClass"; DataTable dt = DBHelper.GetDataSet(sql); List<NewsClass> list = new List<NewsClass>(); foreach (DataRow dr in dt.Rows) { NewsClass newsclass = new NewsClass(); newsclass.NewsCId = (int)dr["NewsCId"]; newsclass.NewsCName = dr["NewsCName"].ToString(); list.Add(newsclass); } return list; }
public static List<NewsClass> GetAllNewsClass(string txtName) { string sql = "select * from NewsClass where name = txtName"; DataTable dt = DBHelper.GetDataSet(sql); List<NewsClass> list = new List<NewsClass>(); foreach (DataRow dr in dt.Rows) { NewsClass newsclass = new NewsClass(); newsclass.NewsCId = (int)dr["NewsCId"]; newsclass.NewsCName = dr["NewsCName"].ToString(); list.Add(newsclass); } return list; } 写个带参的方法,参数就是文本框的值 调用的时候 GetAllNewsClass(this.TxtName.text);
------解决方案--------------------
up 1l
string sql = "select * from NewsClass where name like '%"+Text.Text+"%'";
主要是这句
------解决方案--------------------
public DataSet GetList(string strWhere) { StringBuilder strSql=new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM News "); if(strWhere.Trim()!="") { strSql.Append(" where " + strWhere + " order by id desc"); } return DbHelperSQL.Query(strSql.ToString()); }