473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

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.OnDataBindin g(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.CloseConnect ion);
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,
Nov 18 '05 #1
1 5292
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,

"Sachin Kuchinad" wrote:
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.OnDataBindin g(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.CloseConnect ion);
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,

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sachin Kuchinad | last post by:
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...
3
by: Support | last post by:
Hi All, I am working in VB.NET. I have a data bound control (combobox) which I want to fill with a certain field of my table from database ( SQL as backend). The issue is, I want these values to...
12
by: Art | last post by:
Hi, I've got a number of ListBoxes that hold data from an Access database. On another tab of my form I need the user to use a ComboBox to choose one of the items from one of the ListBoxes. I...
1
by: A. Spiehler | last post by:
I'm trying to fill a listBox control with string members from an array of objects. I think using data binding is supposed to be the easiest way to do this. I've never used data binding before and...
5
by: heddy | last post by:
I have a listbox that gets populated in code by a reader result set from a stored proc on SQL Server 2005. In building this I created a set of test rows in the DB and the code runs fine and...
0
by: spowel4 | last post by:
VB 2005: Using an xml file as the data source, I need to fill a listbox with data based upon what was selected in a combobox. In other words, my data consists of a list of customers in a...
1
by: spowel4 | last post by:
VB 2005: Using an xml file as the data source, I need to fill a listbox with data based upon what was selected in a combobox. In other words, my data consists of a list of customers in a...
1
by: Shimon Sim | last post by:
I can't figure out how to bind ComboBox inside of ListView or ListBox. How do I set ComboBox.ItemsSource property? I don't see the way to do it in code and not in XAML. I have Collection that is...
10
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi, Problem: How can I databind (or put) a SqlServer query's row return of 115,000 items into a ComboBox quickly? Not much longer than a matter of seconds, that is... Scenario: I am...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.