views:

341

answers:

3

Hi,

I am developing a CMS that using database based on Joomla ! In Joomla db, we have 2 table :

+----------+
|Categories|
+----------+
id
title
...

+-------+
|Content|
+-------+
id
title
catid
...

I have a query below :

SqlQuery q = new Select("*")
                         //.Top("1")
                         .From(JosContent.Schema)
                         .InnerJoin(JosUser.IdColumn, JosContent.CreatedByColumn)
                         .InnerJoin(JosCategory.IdColumn, JosContent.CatidColumn)
                         .Where("catid").IsEqualTo(catId);

And in the ASPX page, I show data like that :

Tite : <%# DataBinder.Eval(Container.DataItem, "title") %>
In category : <%# DataBinder.Eval(Container.DataItem, "title") %> 
// Category tite not Content title, but ASP.NET think it is Content title :-(

Please help me fix it ? How to discean between that ?

Thanks alot !

+4  A: 

You can refer to the title of Categories table by: Categories.title and the title of Content table by: Content.title. Sorry if I misunderstood your question.

Alan Haggai Alavi
+1  A: 

In your select you could do like Alan said, and then use AS to change what you reference them as later. (I don't specifically know ASP, i'm a PHP programmer but I assume it fairly similary).

Something like

SELECT *, Categories.title AS categoryTitle, Content.title AS contentTitle ... ...

And then you can refer to categoryTitle or contentTitle.

Boushley
Hi,I worked with PHP from 2003 to 2007, however now I am interested with ASP.NET :-)I knew the query you posted above, but now I using SubSonic (http://subsonicproject.com, http://subsonicproject.com/querying/select-queries/) - a Data Access Layer for .NET. As you see, the query I posted above that is not like classical SQL query.I just want to know how to write a SQL in SubSonic, not classic SQL.Thanks !
Shinichi
A: 

Hi all,

I have finised it :)

SqlQuery q = new Select("*", "jos_Categories.title AS 'CatTitle'")
                         //Select("*", "CatTitle = jos_Categories.title")
                         //Select("*", "CatTitle = JosCategory.TitleColumn")
                         //.Top("1")
                         .From(JosContent.Schema)
                         .InnerJoin(JosUser.IdColumn, JosContent.CreatedByColumn)
                         .InnerJoin(JosCategory.IdColumn, JosContent.CatidColumn)
                         .Where("catid").IsEqualTo(catId);

Thanks ... Google :-)

Shinichi