Murray Brown
asked on
VB.net SQL Find first and last text items in a column
Hi
I use the following VB.net code to find the maximum value in numeric and date columns
How do I find the maximum or minimum of an text column where for instance "Albert" would
be the minimum and "Zach" would be the maximum
Function oMaximum_in_Column(ByVal oTableName As String, ByVal oColumnName As String) As String
Try
Dim oSQL As String
oSQL = "Select Max([" & oColumnName & "]) As MyMax From [" & oTableName & "]"
Dim cn As New SqlConnection(Globals.This AddIn.oRIG HT.lblConn ectionStri ng.Text)
Dim cmd As New SqlCommand(oSQL, cn)
cmd.CommandTimeout = My.Settings.Timeout
cn.Open()
oMaximum_in_Column = cmd.ExecuteScalar.ToString
Catch ex As Exception
oMaximum_in_Column = "N/A"
End Try
End Function
I use the following VB.net code to find the maximum value in numeric and date columns
How do I find the maximum or minimum of an text column where for instance "Albert" would
be the minimum and "Zach" would be the maximum
Function oMaximum_in_Column(ByVal oTableName As String, ByVal oColumnName As String) As String
Try
Dim oSQL As String
oSQL = "Select Max([" & oColumnName & "]) As MyMax From [" & oTableName & "]"
Dim cn As New SqlConnection(Globals.This
Dim cmd As New SqlCommand(oSQL, cn)
cmd.CommandTimeout = My.Settings.Timeout
cn.Open()
oMaximum_in_Column = cmd.ExecuteScalar.ToString
Catch ex As Exception
oMaximum_in_Column = "N/A"
End Try
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER