I have a ListBox on .aspx web page in which I am trying to fetch the data from the DB. The query is in the form of a stored procedure and the following is the ListBind(string queryPart) method that I am using.
private void ListBind(string queryPart)
{
SqlDataAdapter adp = new SqlDataAdapter("Retrieve", ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
DataSet ds = new DataSet();
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
adp.SelectCommand.Parameters.Add("@s1", SqlDbType.NVarChar, 255).Value = queryPart;
adp.SelectCommand.Parameters.Add("@s2", SqlDbType.NVarChar, 255).Value = DropDownList1.SelectedItem.ToString();
adp.Fill(ds);
ListBox1.DataSource = ds;
ListBox1.DataBind();
}
The problem is that I do not get any data into my ListBox and it remains empty, with no errors. Tried to find my putting breakpoints but couldn’t find the reason.
I have a similar method which uses a diferent procedure without parameters to bind another dropdown list in my webpage and is working fine. So, something is wrong here. Any suggestions?
You could use SQL profiler to watch the procedure invocation to see what parameters you’re actually using and then try running it directly in SSMS. Equally just break after assigning the parameters.
But I’d bet it’s the selected item parameter – you may want to look at one of the other “selected” properties (eg SelectedValue) if it isn’t populated.