Access datasourcerow from a joined table

2 posts, 0 answers
  1. Greg
    Greg avatar
    12 posts
    Member since:
    Jul 2008

    Posted 26 Feb 2013 Link to this post

    Using SQLDataSource, so please provide a solution with this rather than an alternative unless it cannot be done. Thanks

    TableA and TableB from the same database

    My "ItemsRequested" for the combobox has this string setup and it works fine.

    Dim sql as string = "SELECT TOP 10 B.serialnumber,  A,column, B,Column FROM DB.dbo.TableA A, DB.dbo.TableB B Where B.column LIKE'" + e.Text + "%' and B.column!='CL' order by B.column"

    My problem is on the "ItemBound" method.

    e.Item.Text = e.Item.Attributes("column") + ", "+e.Item.Attributes("column") + ", " +e.Item.Attributes("column")

    The column name has to be the colum from TableB.  In other words  B.Colmn.
    Putting in B.Column of course won't work as follows...
    e.Item.Text = e.Item.Attributes("B.serialnumber") + ", "+e.Item.Attributes("column") + ", " +e.Item.Attributes("column")

    So with this join involved how do a pull this information specifically from the joined table column? B.Column

    Thanks!
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 01 Mar 2013 Link to this post

    Hi Greg,

    Try to change the SQL string like the following:

    Dim sql as string = "SELECT TOP 10 B.serialnumber,  A.Column AS [columnA], B.Column AS [columnB] FROM DB.dbo.TableA A, DB.dbo.TableB B Where B.column LIKE'" + e.Text + "%' and B.column!='CL' order by B.column"
    then you should be able to access the columns from the joined tables:
    e.Item.Text = e.Item.Attributes("columnA") + ", "+e.Item.Attributes("columnB") + ", " +e.Item.Attributes("column")


    Greetings,
    Hristo Valyavicharski
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top