Tuesday, September 15, 2009

Insert Data member & Value Member in ComboBox Using C# ?

int get = Convert.ToInt32(comboBox2.SelectedValue);
string str = "select district_id,district_name from district where state_id=" + get + "";
da = new SqlDataAdapter(str, con);
da.Fill(ds);
comboBox3.DataSource = ds.Tables[0];
int j = 0;
while (j < ds.Tables[0].Rows.Count)
{
comboBox3.DisplayMember = "district_name";
comboBox3.ValueMember = "district_id";
j++;
}
con.Close();
da.Dispose();
ds.Clear();

No comments: