c#.net中怎样用DataGrid控件显示Sql Server数据库中的内容呢
如题
------解决方案--------------------string source= "server=(local);uid=sa;database=northwind ";
string customers= "select * from Customers ";
SqlConnection con=new SqlConnection(source);
SqlDataAdapter da=new SqlDataAdapter(customers,con);
DataSet ds=new DataSet();
da.Fill(ds, "Customers ");
DataGrid1.SetDataBinding(ds, "Customers ");
------解决方案--------------------string source= "server=(local);uid=sa;database=northwind ";
string customers= "select * from Customers ";
SqlConnection con=new SqlConnection(source);
SqlDataAdapter da=new SqlDataAdapter(customers,con);
DataSet ds=new DataSet();
da.Fill(ds, "Customers ");
dataGrid1.DataSource=ds.Tables[0];
------解决方案--------------------string source= "server=(local);uid=sa;database=northwind ";
string customers= "select * from Customers ";
SqlConnection con=new SqlConnection(source);
SqlDataAdapter da=new SqlDataAdapter(customers,con);
DataSet ds=new DataSet();
da.Fill(ds, "Customers ");
dataGrid1.DataSource=ds.Tables[0];
dataGrid1.DataBind();