Calling a SQL Sever query returns in correct value
Posted on 2005-04-08
I have a query on a MS SQL Server called vMaxID that has this code:
SELECT MAX(RefID) AS Expr1
When I run the query in SQL Server; it returns the maximum value in that field, however, when I call the query in VB.NET, I get a different number.
The data in the field has previously been generated by a MS Access program that takes the max value and adds 7 to it to get the new RefID. I'm trying to code a complimentary app that does the same thing, but the max value I get in my vb code is where the first blank in the series is, not the maximum of the field. (i.e. if the data in the column is 1, 8, 15, 22; my code returns 1 while the query in SQL server returns 22).
My vb.net code is this:
Public Shared cn As SqlConnection
Public Shared da As SqlDataAdapter
Public Shared ds As DataSet
Public Shared sConn As String 'connection string info
addDataBind(sConn, "SELECT * FROM vMaxID", "getID")
Shared Sub addDataBind(ByVal connString As String, ByVal sqlStatement As String, ByVal tableName As String)
cn = New SqlConnection(connString)
da.SelectCommand = New SqlCommand(sqlStatement, cn)
I need to get the max value from the RefID column; not fill in the holes in the series.