Home All Groups Group Topic Archive Search About
Author
14 Dec 2005 4:01 PM
Jamie Sutherland
Hi,
My page has a repeater control on it which puls data from my sql db. the
query string I have has several fields of the same name but from different
tables(shown below). On my aspx page I have the following:
<asp:Repeater id="rprActiveOp" runat="server">
    <ItemTemplate>
     <%# DataBinder.Eval(Container, "DataItem.title") & " " &
DataBinder.Eval(Container, "DataItem.firstname") & " " &
DataBinder.Eval(Container, "DataItem.lastname")%>
     <br>
     <%# databinder.Eval(Container, "DataItem.College_Name") %>
    </ItemTemplate>
</repeater>

How do I use the other fields with the same name but from the different
tables?


Dim strsql As String = "SELECT tbl_user_opps.opp_id, tbl_user_opps.Status,
tbl_User_Details.Title, tbl_User_Details.Firstname,
tbl_User_Details.Lastname, " & _
        "tbl_colleges.College_Name, tbl_colleges.Address1,
tbl_colleges.Address2, tbl_colleges.Town, tbl_colleges.County,
tbl_colleges.PostalCode, " & _
        "tbl_colleges.Telephone, tbl_colleges.Website, tbl_colleges.Title,
tbl_colleges.Firstname, tbl_colleges.lastname, tbl_colleges.JobTitle, " & _
        "tbl_opportunities.Opp_Name FROM tbl_colleges INNER JOIN
tbl_User_Details ON tbl_colleges.College_Id = tbl_User_Details.College_Id
INNER JOIN " & _
        "tbl_opportunities INNER JOIN tbl_user_opps ON
tbl_opportunities.opp_id = tbl_user_opps.opp_id ON tbl_User_Details.Username
= tbl_user_opps.Username " & _
        "WHERE (tbl_user_opps.opp_id ='15') AND (tbl_user_opps.Status =
'Approved')"
        Dim cmd As New SqlCommand(strsql, conn)
        Try
            conn.Open()
            rprActiveOp.DataSource = cmd.ExecuteReader
            rprActiveOp.DataBind()
        Catch ex As Exception
            Throw New Exception(ex.Message)



Thanks
Jamie

Author
15 Dec 2005 3:22 AM
Christopher Reed
Use field alias within your query.  For example,

SELECT tbl_user_detail.lastname AS user_lastname, tbl_colleges.lastname AS
college_lastname, ....

Then use the alias as you would the column name in your Repeater.

Hope this helps!
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

Show quoteHide quote
"Jamie Sutherland" <ja***@sutherlandwest.plus.comnospam> wrote in message
news:uRvKWeMAGHA.2708@TK2MSFTNGP12.phx.gbl...
> Hi,
> My page has a repeater control on it which puls data from my sql db. the
> query string I have has several fields of the same name but from different
> tables(shown below). On my aspx page I have the following:
> <asp:Repeater id="rprActiveOp" runat="server">
>    <ItemTemplate>
>     <%# DataBinder.Eval(Container, "DataItem.title") & " " &
> DataBinder.Eval(Container, "DataItem.firstname") & " " &
> DataBinder.Eval(Container, "DataItem.lastname")%>
>     <br>
>     <%# databinder.Eval(Container, "DataItem.College_Name") %>
>    </ItemTemplate>
> </repeater>
>
> How do I use the other fields with the same name but from the different
> tables?
>
>
> Dim strsql As String = "SELECT tbl_user_opps.opp_id, tbl_user_opps.Status,
> tbl_User_Details.Title, tbl_User_Details.Firstname,
> tbl_User_Details.Lastname, " & _
>        "tbl_colleges.College_Name, tbl_colleges.Address1,
> tbl_colleges.Address2, tbl_colleges.Town, tbl_colleges.County,
> tbl_colleges.PostalCode, " & _
>        "tbl_colleges.Telephone, tbl_colleges.Website, tbl_colleges.Title,
> tbl_colleges.Firstname, tbl_colleges.lastname, tbl_colleges.JobTitle, " &
> _
>        "tbl_opportunities.Opp_Name FROM tbl_colleges INNER JOIN
> tbl_User_Details ON tbl_colleges.College_Id = tbl_User_Details.College_Id
> INNER JOIN " & _
>        "tbl_opportunities INNER JOIN tbl_user_opps ON
> tbl_opportunities.opp_id = tbl_user_opps.opp_id ON
> tbl_User_Details.Username = tbl_user_opps.Username " & _
>        "WHERE (tbl_user_opps.opp_id ='15') AND (tbl_user_opps.Status =
> 'Approved')"
>        Dim cmd As New SqlCommand(strsql, conn)
>        Try
>            conn.Open()
>            rprActiveOp.DataSource = cmd.ExecuteReader
>            rprActiveOp.DataBind()
>        Catch ex As Exception
>            Throw New Exception(ex.Message)
>
>
>
> Thanks
> Jamie
>