473,725 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue With Binding Of A DataReader to a Drop-Down or List Box 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>

Nov 18 '05 #1
1 1827
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>

Nov 18 '05 #2

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

Similar topics

5
5764
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
2
1655
by: Donald Williamson | last post by:
I have a DataReader that I am binding to a Repeater control. In the DataReader, I have two fields: 'Name1' and 'Name2' 'Name1' will always have a person's name. Name2 periodically has a person's name. So the question is if there is a value in 'Name2', I want to display only that name. Otherwise, display 'Name1' Any help on how to do this? Using VS.NET - vb
4
1956
by: Brian Conway | last post by:
I need some help on binding a datareader to a dropdown box. I have included the code for the dropdown below. It builds with no errors, but returns no results. Any help would be appreciated. private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { OleDbConnection conn = new OleDbConnection("DataSource=ntdrp001.world;
5
18540
by: sck10 | last post by:
Hello, I have a GridView that is using the following to connect to a SQL Server 2000 stored procedure: <asp:SqlDataSource ID="dsWebDocList" SelectCommand="sp_web_WebDocument" ConnectionString="<%$ ConnectionStrings:cnnSQL_Connect %>" Runat="server"> <SelectParameters> <asp:Parameter Type="String" DefaultValue="FindWebDocAll"
5
2905
by: Ashwani Gaur | last post by:
Hi all, It may be a very simple query, but i am stuck with having millions of record showing instantly in chunks of 100 or 200 record(not a paging concept), in vb i use to bind the data to ado datacontrol which is binded to datagrid and data is instantly shown using ado events and methods in a user friendly manner i.e data is shown and fetched simultaneously.
3
2124
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.
3
3347
by: tshad | last post by:
I am using VS 2003 and trying to build a standalone application. I have been writing all my asp.net work using DW and am just now trying to build a application that will read some of the tables I had written out from my web apps. I can get my DataReader to read my data fine. But I wanted to use a DataGrid, but it is apparently completely different???? I can do:
17
2380
by: Alan Silver | last post by:
Hello, I have a generic method in a utility class that grabs an sqldatareader and returns it. Due to the fact that (AFAIK), you can't close the database connection before you've read the data, this method doesn't close it, it just returns the datareader. The calling code uses the datareader and then just lets it drop out of scope, to be picked up by the garbage collector. Is this a problem? A friend of mine suggested to me that not...
7
3398
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because internally the DataAdapter uses the DataReader... so whats the deal of writing a method that converts a DataReader into a DataTable ? Thanks!
5
1212
by: RAB | last post by:
I have the following code: <%@ Page Language="VB" %> <script runat="server"> Function GetName() As System.Data.IDataReader Dim connectionString As String = 'path to datasource Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection (connectionString)
0
8888
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
9401
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
9257
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
9176
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
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
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
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.