VS2008中c#程序,如何用数据集实现查询数据库的数据?
1个回答
展开全部
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");
采纳哦
采纳哦
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询