Link to home
Start Free TrialLog in
Avatar of garyinmiami2003
garyinmiami2003Flag for United States of America

asked on

Retrieving a Max value from a table and storing in VB.net

My SQL statement looks like this
select max(SEQ_NO) AS expr1 where fld1 = 'strFld1'.  According to the data this should return a number from 01 to 99, or null.  I can execute the query separate from the program and it works.  I need to know how to return the single value to process it.  I am used to returning the values to a dataset and placing in a grid.  I have 2 problems:  It is reurning a 0 or null that produces an error when I try to return it t to a dataset.  2nd.  How may I best refer to just one value returned from the query?  
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Can you post a section of code showing how you are attempting to get the results?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi garyinmiami2003;

Your SQL select statement needs a FROM clause to identify the table

select max(SEQ_NO) AS expr1 FROM TableName where fld1 = 'strFld1'

Fernando
Avatar of garyinmiami2003

ASKER

Dim money As Decimal = CDec(cmd.ExecuteScalar())


Was the statement I needed.  Fernando, Thanks again for the high quality assistance
Not a problem, glad I was able to help. ;=)