C#中,當從數據庫中查詢到數據,以DataTable類型返回后,如果需要對DataTable中的數據進行篩選,可以選擇下面的方式


 DataRow[] dr = _deptCodeDt.Select(string.Format(" ward_code = '{0}'", LocalSetting.WardCode));
                    if (dr.Length <= 0)
                        return;
                    DataTable tempT = new DataTable();
                    tempT = dr[0].Table.Clone();        //克隆表結構
                    DataSet tempDs = new DataSet();
                    tempDs.Tables.Add(tempT);          //添加到輔助數據集中
                    tempDs.Merge(dr);                  //利用數據集合並行集到表

                    deptCmBox.DataSource = tempDs.Tables[0];
                    deptCmBox.DisplayMember = "ward_name";
                    deptCmBox.ValueMember = "ward_code";

備注:1._deptCodeDt 為從數據中中返回的DataTable

        2.deptCmBox 是一個下拉列表空間的name


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM