我将要查询的sqlserver数据库的表导入visual studio 2010,用c#写一个程序,按一个按钮将数据源中的表通过查询语句显示在datagridview中
SqlConnection con = new SqlConnection("Data Source=DESKTOP-5KVS068\\SQLEXPRESS;Initial Catalog=EducationalAdministrationSystem;Persist Security Info=True;User ID=sa;Password=eupsoft");
con.Open();//打开连接
SqlDataAdapter sda = new SqlDataAdapter("select [OrgansisationName] from SQLDesign ", con);//读取表数据
DataTable dt = new DataTable();//dt是一个表类型。
sda.Fill(dt);//把sda读取的数据填到dt里
dataGridView1.DataSource = dt;//把dt的内容绑定到Gridview1里显示。