VS2008中c#程序,如何用数据集实现查询数据库的数据?
- 提问者网友:精神病院里
- 2021-05-14 05:09
- 五星知识达人网友:神也偏爱
- 2021-05-14 06:03
SqlConnection conn = new SqlConnection("Data Source = DONGFANG\\SQLServer2005; Initial Catalog = AdventureWorks; User ID = sa; Password = 111111");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECt * FROM HumanResources.Department", conn);
conn.Close();
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "HumanResources.Department");
DataTable dt = new DataTable();
dt = ds.Tables["HumanResources.Department"];
DataRow row = dt.NewRow();
row["Name"] = "Test111";
row["GroupName"] = "GroupTest111";
row["ModifiedDate"] = "2009-10-11";
dt.Rows.Add(row);
DataColumn column = new DataColumn("Hello", typeof(string));
dt.Columns.Add(column);
dataGridView1.DataSource = dt.DefaultView;
da.Update(ds, "HumanResources.Department");