我试图将SQL数据库中的值加载到组合框中,然后在按钮单击后,我想将所选组合框的值保存到变量中。
这是我的代码:
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
string strCmd = "select id,Prijmeni from Osoba";
SqlCommand cmd3 = new SqlCommand(strCmd, con);
SqlDataAdapter da = new SqlDataAdapter(strCmd, con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "Prijmeni";
comboBox1.ValueMember = "id";
comboBox1.Enabled = true;
cmd3.ExecuteNonQuery();
con.Close();
private void Ulozit_Click(object sender, EventArgs e)
{
//How i could save selected value of combobox to variable Value1 ???
}
请问您有什么想法吗?