用按钮事件绑定DataGridView的数据源
private string server = "127.0.0.1";
private string user = "sa";
private string pwd = "123456";
private string connstr = "";
private string sql = "";
在按钮事件中添加以下代码:
connstr = "server=" + server + ";uid=" + user + ";pwd=" + pwd + ";database=ado";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
sql = "select * from 员工管理表";
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataAdapter ada = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
ada.Fill(ds, "员工管理表");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "员工管理表";
conn.Close();
conn.Dispose();