日期:2014-05-19  浏览次数:20805 次

[求助]C#连接数据库超级简单问题
string   ConnStr   =   "SERVER=(local);USER   ID=sa;PWD=;DATABASE=abc ";
string   strsql   =   "select   *   from   Member ";
SqlConnection   Conn   =   new   SqlConnection(ConnStr);
SqlCommand   mycommand   =   new   SqlCommand(strsql,   Conn);
Conn.Open();
SqlDataReader   mySqlDataReader   =   mycommand.ExecuteReader();
Conn.Close();

提问
DataTable   myTable   =   new   DataTable();
如何把数据集放到myTable里面?


------解决方案--------------------
换成SqlDataAdapter:

DataTable myTable = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(mycommand,ConnStr);
adapter.Fill(myTable );