//先设置datagridview的visible设置成false
public static string 连接字符串 = "Data Source=LocalHost实例名;Initial Catalog=数据库名;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(连接字符串);
string cmdText = "SELECT 。。。。。。。";
SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
DataTable dt = new DataTable();
sqlConnection.Open();
sqlDataAdapter.Fill(dataTable);
sqlConnection.Close();
dataGridView1.DataSource=dt;
dataGridView1.Visible = true;
先把datagridview的visible设置成false。
双击button生成事件
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Visible = true;
}
连接数据库的话,你要是要直接绑定数据源还是代码实现?