نقل قول: bind کردن یه combo box ?
دوست من این کدیه که الان نوشتم ولی مسلما تنها راه نیست
private void btnfill_Click(object sender, EventArgs e)
{
try
{
SqlConnection sc = new SqlConnection(@"data source = MOYA-LAP\MOHAMMADSERVER ; database = test; user id = sa ; password = moyamoya");//@"data source = moya-pc\mohammadserver ; database =test;integrated security = true");
SqlCommand cmd = new SqlCommand("select name from student", sc);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable table = new DataTable();
sda.Fill(table);
foreach (DataRow dr in table.Rows)
{
cbox1.Items.Add(dr[0]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
نقل قول: bind کردن یه combo box ?
به روش زیر هم میشه!
string str = "select IDS from Farm";
str += comboBox1.Text;
SqlDataAdapter Da = new SqlDataAdapter(str, con);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Table");
comboBox2.DataSource = Ds;
comboBox2.DisplayMember = "Table.IDS";