-2
このコードを使用して、テーブルSQLデータベースからドロップダウンリストを入力します。 私はドロップダウンリストの各行のID、FirstName、LastNameを表示する必要があります。例えばID +姓と行の姓のテーブルからドロップダウンリストを入力する方法
:
1-Sara Sindra
2-Michel Lafra.
が、ドロップダウンリストに表示される自分のコードだけのIDを持ちます。
public void Load_Combo(string Query, ComboBox cb)
{
string ConnectionString = @"Data Source=.\sqlexpress;AttachDbFilename=|DataDirectory|\mydatabase.mdf;user id = sa;password = 1111111111";
SqlConnection connection = new SqlConnection();
cb.Items.Clear();
connection.ConnectionString = ConnectionString;
connection.Open();
SqlDataAdapter adaptor = new SqlDataAdapter(Query, connection);
DataTable dtt = new DataTable();
adaptor.Fill(dtt);
for (int i = 0; i < dtt.Rows.Count; i++)
cb.Items.Add(dtt.Rows[i][0].ToString());
connection.Close();
}
private void btn1_Click(object sender, EventArgs e)
{
Load_Combo("SELECT ID , FName + ' ' + LName AS Fullname FROM studentstbl", cmb_cash1);
}
これはウェブフォームとしてタグ付けする必要があります – fireydude