473,657 Members | 2,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Http Exception: DataBinder.Eval : 'System.Data.Co mmon.DbDataReco rd' does not contain a property with the name Davolio. at System.Web.UI.D ataBinder.GetPr opertyValue(Obj ect container, String propName) at System.Web.UI.D ataBinder.GetPr opertyValue(Obj ect container, String propName, String format) at System.Web.UI.W ebControls.List Control.OnDataB inding(EventArg s e) at System.Web.UI.C ontrol.DataBind () at TestApp.WebForm 1.getEmpDetails () in c:\inetpub\wwwr oot\testapp\web form1.aspx.cs:l ine 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=New123 4;Persist Security Info=True;User ID=sa;Initial Catalog=Northwi nd;Data Source=IND-SPZ4D2K0319");
SqlCommand oSQLCmd;
SqlDataReader oSQLDataRead;
try
{ oSQLConn.Open() ;
oSQLCmd = new SqlCommand("sel ect * from employees",oSQL Conn);
oSQLCmd.Command Type = CommandType.Tex t;

oSQLDataRead = oSQLCmd.Execute Reader(CommandB ehavior.CloseCo nnection);
if(oSQLDataRead .Read())
{
//string strName = oSQLDataRead.Ge tValue(1).ToStr ing() + " " + oSQLDataRead.Ge tValue(2).ToStr ing();
//ddl01.Items.Add (strName);
ddl01.DataTextF ield = oSQLDataRead.Ge tValue(1).ToStr ing();
//ddl01.DataValue Field = oSQLDataRead.Ge tValue(1).ToStr ing();
ddl01.DataSourc e = 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 5309
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.Http Exception: DataBinder.Eval : 'System.Data.Co mmon.DbDataReco rd' does not contain a property with the name Davolio. at System.Web.UI.D ataBinder.GetPr opertyValue(Obj ect container, String propName) at System.Web.UI.D ataBinder.GetPr opertyValue(Obj ect container, String propName, String format) at System.Web.UI.W ebControls.List Control.OnDataB inding(EventArg s e) at System.Web.UI.C ontrol.DataBind () at TestApp.WebForm 1.getEmpDetails () in c:\inetpub\wwwr oot\testapp\web form1.aspx.cs:l ine 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=New123 4;Persist Security Info=True;User ID=sa;Initial Catalog=Northwi nd;Data Source=IND-SPZ4D2K0319");
SqlCommand oSQLCmd;
SqlDataReader oSQLDataRead;
try
{ oSQLConn.Open() ;
oSQLCmd = new SqlCommand("sel ect * from employees",oSQL Conn);
oSQLCmd.Command Type = CommandType.Tex t;

oSQLDataRead = oSQLCmd.Execute Reader(CommandB ehavior.CloseCo nnection);
if(oSQLDataRead .Read())
{
//string strName = oSQLDataRead.Ge tValue(1).ToStr ing() + " " + oSQLDataRead.Ge tValue(2).ToStr ing();
//ddl01.Items.Add (strName);
ddl01.DataTextF ield = oSQLDataRead.Ge tValue(1).ToStr ing();
//ddl01.DataValue Field = oSQLDataRead.Ge tValue(1).ToStr ing();
ddl01.DataSourc e = 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
1826
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 not happenm , i have no clue what the problem is I am attaching the error <font color='red' >
3
2116
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 fill the combo at the index specified by me, ie, not the usual 0,1,2.... by default. Also, not dataset, but I am using dataReader. Can anyone send me the sample code for the same? Thanks for your help.
12
1720
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 have attached the ComboBox to my Access database and this works fine. However, it seems to me that I should be able to attach it to the ListBox that has that same information instead. Can I do this? Art
1
2770
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 am having trouble getting it to do anything. The relevant code is below, followed by a better explanation of what I'm trying to do. // pseudocode start public delegate string StepMethod();
5
2295
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 populates the box. Next I added functionality to add data. This adds data to the DB and then forces the listbox to refresh by clearing it's contents and then re-running the populate code. However, when I add an item and do the refresh, the listbox...
0
1271
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 combobox; once a particular customer is selected I need to populate a listbox with data specific to the selected customer. A sample layout of the xml file: <RECORD> <CUSTOMER_NUMBER>customer number</CUSTOMER_NUMBER> <SHIPTO_ID>ship to id</SHIPTO_ID>...
1
1712
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 combobox; once a particular customer is selected I need to populate a listbox with data specific to the selected customer. A sample layout of the xml file: <RECORD> <CUSTOMER_NUMBER>customer number</CUSTOMER_NUMBER> <SHIPTO_ID>ship to id</SHIPTO_ID>...
1
11024
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 bound to ListBox / ListView and string that should be bound to ComboBox. Thanks, Shimon.
10
5835
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 rebuilding my company's Access 97 VBA database app. It pulls 115,000 items (of account names) from SqlServer and the data is bound to a single Access 97 ComboBox control. My C# version needs to work exactly like this one. Our executive employees want...
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.