TOP

[C#]Select Data into DataView from Database


解決從SQL取得資料後無法直接存至DataView,需從DataSet轉至DataView

SqlConnection conn = new SqlConnection("");
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
string sqlstr = "select * from table";
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
conn.Close();
da.Dispose();

0 意見:

張貼留言