我想在 datagridview 中显示一个指定的列值。示例:从表中user_account
,我想通过account
datagridview 中的列中的文本框数据显示和搜索
这是到目前为止的代码:
private void button3_Click(object sender, EventArgs e)
{
string connectionString = @"Data Source=" + textBox4.Text + ";" + "Initial Catalog=" + textBox1.Text + ";" + "User ID=" + textBox2.Text + ";" + "Password=" + textBox3.Text;
string sql = "SELECT * FROM user_account";
SqlConnection connection = new SqlConnection(connectionString) ;
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "account");
connection.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "account";
}