Issue with Data Reader Binding for ASP.net ComboBox & Listbox cont

G

Guest

Hi All

I am using .NET Framework version 1.0.3705 to build a website.
Now i have made a webform and on that i have added a dropdown to the page

I bind this listbox to a datareader .
This does not happenm , i have no clue what the problem is
I am attaching the error

<font color='red' >
System.Web.HttpException: DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name Davolio. at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) at System.Web.UI.Control.DataBind() at TestApp.WebForm1.getEmpDetails() in c:\inetpub\wwwroot\testapp\webform1.aspx.cs:line 67

</font>

I am attaching the code too!
I have made the connection to the Northwind database , this is easilt available
Please advise what is going wrong if there is a KB article for the same?

<code>

private int getEmpDetails()
{
SqlConnection oSQLConn = new SqlConnection("Password=New1234;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=IND-SPZ4D2K0319");
SqlCommand oSQLCmd;
SqlDataReader oSQLDataRead;
try
{ oSQLConn.Open();
oSQLCmd = new SqlCommand("select * from employees",oSQLConn);
oSQLCmd.CommandType = CommandType.Text;

oSQLDataRead = oSQLCmd.ExecuteReader(CommandBehavior.CloseConnection);
if(oSQLDataRead.Read())
{
//string strName = oSQLDataRead.GetValue(1).ToString() + " " + oSQLDataRead.GetValue(2).ToString();
//ddl01.Items.Add(strName);
ddl01.DataTextField = oSQLDataRead.GetValue(1).ToString();
//ddl01.DataValueField = oSQLDataRead.GetValue(1).ToString();
ddl01.DataSource = oSQLDataRead;
ddl01.DataBind();
}
return 1;
}
catch(Exception ex)
{
Response.Write(ex.ToString());
return -1;
}
}

</code>

Please note when I tried to bind the datareader to a datagrid control it worked perfectly fine. However, it throws up an exception on binding the same to a dataList and combo-box [asp.net] controls.

Any Clue why this happens???


Thanks,
 
G

Guest

Got it guys!!!

The mistake is with my coding... sorry. The way to bind the thing was to assign the DataFieldValue and DataFieldText properties of a combo box or a Listbox to the column names and not to the value as I was doing it.

This solved the problem. So there is not issue with binding as the subject heading says!!!

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top