Previous Thread:   Generating HTML code in the code-behind

8/25/2005 5:42:17 PM    Unexplained error when databinding
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.  
  
--  
  
Nathan Sokalski  
  
njsokalski@hotmail.com  
  
http://www.nathansokalski.com/



8/25/2005 5:58:56 PM    Re: Unexplained error when databinding
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 Sokalski wrote:

8/26/2005 12:00:13 AM    Re: Unexplained error when databinding
Nathan:  
  
Or you could just rename the fields in the database to MEmail and AEmail  
  
Bob

8/26/2005 12:03:16 AM    Re: Unexplained error when databinding
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" <njsokalski@hotmail.com> wrote in message  
  
news:O7mAc3bqFHA.208@TK2MSFTNGP10.phx.gbl...

8/26/2005 7:42:56 AM    Re: Unexplained error when databinding
That is something I never would do. The method of ng is in my opinion the  
  
right one.  
  
Just my thought,  
  
Cor

8/26/2005 12:01:03 PM    Re: Unexplained error when databinding
Cor:  
  
Why not?  Wouldn't it make things a little easyer to inerpret and provide  
  
for less aliases?  
  
Bob

8/26/2005 1:59:03 PM    Re: Unexplained error when databinding
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