0

指定した列の値を datagridview に表示したい。例:テーブルからdatagridviewuser_accountのカラムからテキストボックスのデータを表示・検索したいaccount

これまでのコードは次のとおりです。

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";
    }
4

2 に答える 2

1
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 account 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;

    }
于 2013-09-05T04:46:05.807 に答える
0

解決:

        private void button3_Click(object sender, EventArgs e)
    {
        string connectionString = @"Data Source=" + textBox4.Text + ";" + "Initial Catalog=" + "lin2db" + ";" + "User ID=" + textBox2.Text + ";" + "Password=" + textBox3.Text;
        string sql = "SELECT account ,pay_stat FROM user_account where account='" + textBox7.Text + "' ";          
        SqlConnection connection = new SqlConnection(connectionString) ;
        SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
        DataSet ds = new DataSet();
        connection.Open();
        dataadapter.Fill(ds, "pay_stat");
        connection.Close();
        dataGridView1.DataSource = ds;
        dataGridView1.DataMember = "pay_stat";


    }

ご協力ありがとう御座います。

于 2013-09-05T09:17:47.603 に答える