Forum Moderators: open

Message Too Old, No Replies

How can i use MAX or MIN?

         

ajifri

11:52 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



Hi,
I have ms access db with one table let's call MyTable with two fields ID and Writer.
The question is how can I display (MAX) writer name in the label.text by using ASP.Net/vb.net?

"SELECT MAX(MyTable.Writer) FROM MyTable"

Best Regads,
A. J.

WebJoe

12:46 am on Nov 5, 2003 (gmt 0)

10+ Year Member



To my knowledge that's a SQL-statement and has nothing to do with the language you use to generate your content (ASP, ASP.NET, PHP etc), and it should work with something like:
SELECT MyTable.Writer FROM MyTable WHERE MyTable.Writer = (SELECT MAX(MyTable.Writer) FROM MyTable)

I'm almost certain that there's an easier way, but that's the only one I can think of...

bmcgee

1:43 am on Nov 5, 2003 (gmt 0)

10+ Year Member



SELECT TOP 1 MyTable.Writer FROM MyTable ORDER BY MyTable DESC

bmcgee

1:44 am on Nov 5, 2003 (gmt 0)

10+ Year Member



errr that should be:
SELECT TOP 1 MyTable.Writer FROM MyTable ORDER BY MyTable.Write DESC

mattglet

4:31 am on Nov 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A.J.,
your select statement didn't work?

-Matt

ajifri

11:47 am on Nov 5, 2003 (gmt 0)

10+ Year Member



Thanks to you all
mattglet , my SQL code worked great, but I don't know how to show the result with ASP.Net/VB.Net (SHY)

Can you help me guys (SHY)

killroy

11:52 am on Nov 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe I'm totally off, but I believe you wonder what is the column name name to use. Try this:

SELECT MAX(MyTable.Writer)AS max_writer FROM MyTable

and use "max_writer" as your column name.

SN

aspdaddy

9:44 pm on Nov 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The SQL is fine, the poster is asking how to put the result of the query into an html control in vb.net

ajifri

11:45 pm on Nov 5, 2003 (gmt 0)

10+ Year Member



Thanks to you all, I found the solution

Dim maxsql as String = "SELECT MAX(MyTable.Writer) FROM MyTable"
Dim myDataAdapter as New OleDbDataAdapter(strSQL, myConnection)
Dim myDataSet as New DataSet()
myDataAdapter.Fill(myDataSet, "MyTable")
Dim Cmd2 as New OLEDBCommand(maxsql, myConnection)
MAX.text = cmd2.executescalar()