C# DataTable Linq查詢
using System.Linq;
SqlConnection conn = new SqlConnection("連線字串");
conn.Open();
DataTable dt = new DataTable();
using (SqlCommand com = new SqlCommand("SELECT * FROM MOC_Base", conn))
{
SqlDataAdapter ad = new SqlDataAdapter(com);
ad.Fill(dt);
}
var query = from data in dt.AsEnumerable()
where data.Field<int>("baseId") == 1
select data; //輸出欄位
foreach (var item in query)
{
//找到物件需要做的事情
}
標籤: c#
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁