Unexplained error when databinding

N

Nathan Sokalski

I am using a DataSet as the DataSource of a DataList in my code. The SQL
used to get the data from the database begins with:


SELECT
members.organization,artists.artist,artists.email,artists.website,members.email
FROM members INNER JOIN artists ON members.memberid=artists.memberid WHERE


Notice that both tables involved in the SELECT statement have a field named
email. First, I do not know how to specify which one I want in my
databinding expressions (I tried DataItem.artists.email and
DataItem.members.email, but that gave me an error too). Second, I know that
my DataSet is getting filled correctly because my first databinding
expression worked (see line 71 in the error). My error is as follows:
Server Error in '/' Application.
--------------------------------------------------------------------------------

DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with
the name email.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinder.Eval:
'System.Data.DataRowView' does not contain a property with the name email.

Source Error:

Line 70: <ItemTemplate>
Line 71: <asp:Label id=lblOrganization1 runat="server" Width="175px"
text='<%# DataBinder.Eval(Container, "DataItem.organization")
%>'></asp:Label>
Line 72: <asp:HyperLink id="lnkPresenterEmail1" runat="server"
Width="175px" text='<%# DataBinder.Eval(Container, "DataItem.email") %>'
NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}")
%>' Target="_blank"></asp:HyperLink>
Line 73: <asp:Label id=lblArtist1 runat="server" Width="125" text='<%#
DataBinder.Eval(Container, "DataItem.artist") %>'></asp:Label>
Line 74: <asp:HyperLink id=lnkEmail1 runat="server" Width="175"
text='<%# DataBinder.Eval(Container, "DataItem.email") %>' NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}") %>'
Target="_blank"></asp:HyperLink>

Source File: D:\Clients\12654\papresenters.org\papresenters.org\search.aspx
Line: 72

Stack Trace:

[HttpException (0x80004005): DataBinder.Eval: 'System.Data.DataRowView' does
not contain a property with the name email.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName) +146
System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
+71
System.Web.UI.DataBinder.Eval(Object container, String expression) +82
ASP.search_aspx.__DataBind__control34(Object sender, EventArgs e) in
D:\Clients\12654\papresenters.org\papresenters.org\search.aspx:72
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem) +127
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource) +683
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +48
System.Web.UI.WebControls.BaseDataList.DataBind() +23
PAPresenters.search.btnSearch_Click(Object sender, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET
Version:1.1.4322.2300



Can anyone help me with this? Thanks.
 
N

ng

The reason you aren't finding 'email' is because SQL databases assign an
arbitrary column name if you have two matching names, or they leave the
qualifier in the name, such as artists.email and members.email. Try
assigning new names to the columns in your SQL statement, like "select
members.email m_email, artists.email a_email" and then use the new
column names in your binding.

Tom


Nathan said:
I am using a DataSet as the DataSource of a DataList in my code. The SQL
used to get the data from the database begins with:


SELECT
members.organization,artists.artist,artists.email,artists.website,members.email
FROM members INNER JOIN artists ON members.memberid=artists.memberid WHERE


Notice that both tables involved in the SELECT statement have a field named
email. First, I do not know how to specify which one I want in my
databinding expressions (I tried DataItem.artists.email and
DataItem.members.email, but that gave me an error too). Second, I know that
my DataSet is getting filled correctly because my first databinding
expression worked (see line 71 in the error). My error is as follows:
Server Error in '/' Application.
--------------------------------------------------------------------------------

DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with
the name email.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinder.Eval:
'System.Data.DataRowView' does not contain a property with the name email.

Source Error:

Line 70: <ItemTemplate>
Line 71: <asp:Label id=lblOrganization1 runat="server" Width="175px"
text='<%# DataBinder.Eval(Container, "DataItem.organization")
%>'></asp:Label>
Line 72: <asp:HyperLink id="lnkPresenterEmail1" runat="server"
Width="175px" text='<%# DataBinder.Eval(Container, "DataItem.email") %>'
NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}")
%>' Target="_blank"></asp:HyperLink>
Line 73: <asp:Label id=lblArtist1 runat="server" Width="125" text='<%#
DataBinder.Eval(Container, "DataItem.artist") %>'></asp:Label>
Line 74: <asp:HyperLink id=lnkEmail1 runat="server" Width="175"
text='<%# DataBinder.Eval(Container, "DataItem.email") %>' NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}") %>'
Target="_blank"></asp:HyperLink>

Source File: D:\Clients\12654\papresenters.org\papresenters.org\search.aspx
Line: 72

Stack Trace:

[HttpException (0x80004005): DataBinder.Eval: 'System.Data.DataRowView' does
not contain a property with the name email.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName) +146
System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
+71
System.Web.UI.DataBinder.Eval(Object container, String expression) +82
ASP.search_aspx.__DataBind__control34(Object sender, EventArgs e) in
D:\Clients\12654\papresenters.org\papresenters.org\search.aspx:72
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem) +127
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource) +683
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +48
System.Web.UI.WebControls.BaseDataList.DataBind() +23
PAPresenters.search.btnSearch_Click(Object sender, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET
Version:1.1.4322.2300



Can anyone help me with this? Thanks.
 
B

Bob

Nathan:

Or you could rename the fields in the database tables to MEmail and AEmail.

Dont forget to clean up the garbage code left behind in the "Windows Form
Designer Generated Code.

Seems to be a problem with VS not doing it when you regenerate the DA's

Today I cleaned up some 2000 lines of code in there. Big diff in
performance.

Bob

Nathan Sokalski said:
I am using a DataSet as the DataSource of a DataList in my code. The SQL
used to get the data from the database begins with:


SELECT
members.organization,artists.artist,artists.email,artists.website,members.email
FROM members INNER JOIN artists ON members.memberid=artists.memberid WHERE


Notice that both tables involved in the SELECT statement have a field
named email. First, I do not know how to specify which one I want in my
databinding expressions (I tried DataItem.artists.email and
DataItem.members.email, but that gave me an error too). Second, I know
that my DataSet is getting filled correctly because my first databinding
expression worked (see line 71 in the error). My error is as follows:
Server Error in '/' Application.
--------------------------------------------------------------------------------

DataBinder.Eval: 'System.Data.DataRowView' does not contain a property
with the name email.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinder.Eval:
'System.Data.DataRowView' does not contain a property with the name email.

Source Error:

Line 70: <ItemTemplate>
Line 71: <asp:Label id=lblOrganization1 runat="server" Width="175px"
text='<%# DataBinder.Eval(Container, "DataItem.organization")
%>'></asp:Label>
Line 72: <asp:HyperLink id="lnkPresenterEmail1" runat="server"
Width="175px" text='<%# DataBinder.Eval(Container, "DataItem.email") %>'
NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}")
%>' Target="_blank"></asp:HyperLink>
Line 73: <asp:Label id=lblArtist1 runat="server" Width="125" text='<%#
DataBinder.Eval(Container, "DataItem.artist") %>'></asp:Label>
Line 74: <asp:HyperLink id=lnkEmail1 runat="server" Width="175" text='<%#
DataBinder.Eval(Container, "DataItem.email") %>' NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}") %>'
Target="_blank"></asp:HyperLink>

Source File:
D:\Clients\12654\papresenters.org\papresenters.org\search.aspx Line: 72

Stack Trace:

[HttpException (0x80004005): DataBinder.Eval: 'System.Data.DataRowView'
does not contain a property with the name email.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName) +146
System.Web.UI.DataBinder.Eval(Object container, String[]
expressionParts) +71
System.Web.UI.DataBinder.Eval(Object container, String expression) +82
ASP.search_aspx.__DataBind__control34(Object sender, EventArgs e) in
D:\Clients\12654\papresenters.org\papresenters.org\search.aspx:72
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem) +127
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource) +683
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +48
System.Web.UI.WebControls.BaseDataList.DataBind() +23
PAPresenters.search.btnSearch_Click(Object sender, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2300;
ASP.NET Version:1.1.4322.2300



Can anyone help me with this? Thanks.
 
C

Cor Ligthert [MVP]

Or you could just rename the fields in the database to MEmail and AEmail
That is something I never would do. The method of ng is in my opinion the
right one.

Just my thought,

Cor
 
B

Bob

Cor:

Why not? Wouldn't it make things a little easyer to inerpret and provide
for less aliases?

Bob
 
J

John Horst

Nathan:

Change this:

SELECT
members.organization,artists.artist,artists.email,artists.website,member
s.email
FROM members INNER JOIN artists ON members.memberid=artists.memberid

to this:

SELECT m.organization, a.artist, a.email As AEmail,
a.website, m.email As MEmail
FROM members m
INNER JOIN artists a
ON m.memberid = a.memberid

This is called aliasing the tables and the columns that have the same
name (notice that I put an "m" after members and an "a" after artists;
these are the aliases for the tables). Your datatable (in the dataset)
will use the aliased named (Aemail and Memail). This way you can leave
your database as is.

John
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top