我的数据表;
dtData ID | ID2 -------- 1 | 2 1 | 3 dtData.Select("ID = 1"); one more rows;
我想要行"ID = 1和ID2 = 3"如何制作?
你的意思是这样的吗?:
dtData.Select("ID=1 AND ID2=3");
好的,这就是我做这些事情的方式......
GridFieldDAO dao = new GridFieldDAO(); //Load My DataTable DataTable dt = dao.getDT(); //Get My rows based off selection criteria DataRow[] drs = dt.Select("(detailID = 1) AND (detailTypeID = 2)"); //make a new "results" datatable via clone to keep structure DataTable dt2 = dt.Clone(); //Import the Rows foreach (DataRow d in drs) { dt2.ImportRow(d); } //Bind to my new DataTable and it will only show rows based off selection //criteria myGrid.DataSource = dt2; myGrid.DataBind();
注意在我的Select()中,我将标准放在AND和 OR之间的Parens中
希望这可以帮助!迈克五世
更好地利用这个:
GridFieldDAO dao = new GridFieldDAO(); //Load My DataTable DataTable dt = dao.getDT(); //Get My rows based off selection criteria and copy them directly to datatable DataTable dt2 = dt.Select("(detailID = 1) AND (detailTypeID = 2)").CopyToDataTable();