Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Databinding combobox.with stored procedure
 

Databinding combobox.with stored procedure

Ok, so I have a windows form with just a combo box. I'm able to bind data from a table to the combobox using Bindingsource with a datasource etc. Now when I try to do the same thing pointing to a proc instead of a table I get nothing back. WHile configuring the datasource I can even preview the data comming from the proc so I know it's not the back end. WHat am I missing?


THanks,
Santiago
Santiago Perez
SantiagoPerez  Wednesday, June 03, 2009 6:57 PM
I figured out what was happening, THere was no auto-generated code for the data adapter to fill. In the OnLoad I just wrote the code to make the call and passed in bogus params for the call and it worked. THanks!
Santiago Perez
SantiagoPerez  Thursday, June 04, 2009 4:41 PM
Could you post the code you are using for your binding? That may help us see what you might be doing wrong.
www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Wednesday, June 03, 2009 8:01 PM
I figured out what was happening, THere was no auto-generated code for the data adapter to fill. In the OnLoad I just wrote the code to make the call and passed in bogus params for the call and it worked. THanks!
Santiago Perez
SantiagoPerez  Thursday, June 04, 2009 4:41 PM
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());

}

}
raveendar  Thursday, August 20, 2009 8:52 AM

You can use google to search for other answers

Custom Search

More Threads

• How to bind a combo box to the current item and use a list of possible values to modify the item
• removing a row from a datatable by clicking the row in the datagridview it belongs to
• BindingSource CurrentChanging!
• Referencing tablecell text in an embedded datagrid within a datagrid
• Bound DataSet, update and continue editing
• Field Names with spaces
• Datagridview cell coloring problem
• Rotating rows and columns in DataGridView 2.0
• get index of selected value in combo box
• selecting whole column with a click