tags:

views:

57

answers:

3

Hello!!

I have a problem with the picture rating application that I am working on. I don’t regularly program with C#, so if anyone could help, that would be the best thing that has happened so far to me!!

I am programming in visual studio 2008, the base for the application is made in Microsoft Access.

So what I am trying to do:

I have made a table in Access and I am trying to get some information out of it. The table name is dogodek and it consists of id_dogodek, id_category, title, author, ratings and picture (just URL-s). So I can fill the table in my application, but I have a problem, how to present the picture with the highest rating. I don’t know how to load the information’s from the base and then use it.

This is what I have done!

private void images()
{
    OleDbConnection conn = new OleDbConnection(WebConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
    conn.Open();

    string sql = "SELECT id_dogodek,picture,MAX(ratings) FROM 'dogodek'"; //it do not work


    OleDbDataAdapter da = new OleDbDataAdapter(sql,conn);
    DataSet ds = new DataSet();
    da.Fill(ds);
    //How to load the image to (Image1)??
    Image1.ImageUrl = "images/" + ds.Tables[0].Rows[0]["fotografija"].ToString();

    conn.Close();
}

Please help!!

+1  A: 
SELECT TOP 1 id_dogodek,picture,ratings
FROM 'dogodek'
ORDER BY ratings DESC

MAX(ratings) is only for when you're grouping (GROUP BY), ie if there's another table that has lots of ratings for each id_dogodek.

SteveCav
does 'top 1' work in Access? It might - for some reason I thought it was specific to SQL Server so I left that out as part of my comment.
James Manning
Yep, TOP X is in it. In the GUI query designer it's represented by a "return:" box in the ribbon.
SteveCav
A: 

This should work

SELECT *
FROM
(
   SELECT ROW_NUMBER() over (ORDER BY ratings DESC) AS 'Order' , id_dogodek,picture,ratings
   FROM dogodek
) D
WHERE [Order] =1
Alex
A: 

Thanks for everything, I'll try it out when I get home, I am at work now.

Badak naffas, yes I think that'll do!

I have another question!

How can I send the result (the highest ranked image) to the image1! For the presentation! So that it will be shown when the side is called up.

ALJAZ
Please ask extra questions as separate questions. Do not put questions in answers.
Matt Ellen