数据集和表适配器有什么区别,有人可以用有趣的例子来解释一下。
表适配器如何从 sql server 获取数据?
您使用SqlServer 中的数据DataAdapter
填充。DataSet
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_tblname", conn);
try
{
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd; // Set the select command for the DataAdapter
da.Fill(ds); // Fill the DataSet with the DataAdapter
DataGridView1.DataSource = ds.Tables[0]; // I just displayed the results in a grid view for simplicity. If Asp.Net you will have to call a DataBind of course.
catch (Exception ex)
{
conn.Close();
conn.Dispose();
}