TOP

[C#] Select Data into DataTable from Database


最主要是要將資料取得的資料存在DataTable。

SqlConnection conn = new SqlConnection("");
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
string sqlstr = "select * from " + strtable;
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
DataTable dt = new DataTable();
da.Fill(dt);
conn.Close();
da.Dispose();

參考資料:http://www.wretch.cc/blog/s0341969/33051318

0 意見:

張貼留言