I am trying to bind list of states to combo box could you pls help me
this is my code...
public void LoadState()
{
SqlCommand cmd = new SqlCommand();
//"select St_ID_PK,St_Name from lk_State ORDER BY St_ID_PK", con);
SqlConnection con = new SqlConnection();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_GetStates";
SqlDataAdapter sqlDa = new SqlDataAdapter();
DataSet ds = new DataSet();
con.ConnectionString = ("Data source=DTKEDP;Initial Catalog=IMPEX;uid=sa;password=007;");
try
{
con.Open();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
try
{
sqlDa.SelectCommand = cmd;
//sqlDa.Fill(ds, "SP_GetStates");
DataTable dt = new DataTable();
//dt = ds.Tables[0]; //Where ds is Dataset
cmbState.ItemsSource = ((IListSource)dt).GetList();
cmbState.DataContext = ds.Tables["lk_State"].DefaultView;
cmbState.DisplayMemberPath = "St_Name";
cmbState.SelectedValuePath = "St_ID_PK";
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}