Ver Mensaje Individual
  #5 (permalink)  
Antiguo 04/01/2006, 12:36
astrow25
 
Fecha de Ingreso: enero-2006
Mensajes: 263
Antigüedad: 19 años, 1 mes
Puntos: 1
He probado a hacer lo que me dices y me da 2 errores

1º En el sql me da error en la linea
Select @resultado = MAX(NUMREGISTRO) as NUMREGISTRO from SOCIOS

2º En vb.net el spGetMaxRecord no lo reconoce

Cita:
Iniciado por Andres95
porque probablemente el max te devuelve un record con un cero. (que seria el valor maximo cuando no hay registros).

Si lo que requieres es solo un valor, es recomendable no utilizar un dataset (el reader) sino utilizar un parametro de tipo output en un sp.

Seria algo como :

En el SQL ....

Create procedure spGetMaxRecord
@resultado int output
AS
Set @resultado = 0
Select @resultado = MAX(NUMREGISTRO) as NUMREGISTRO from SOCIOS
Set @resultado = isnull(@resultado,0)



En el Visual Studio.
Código:
        Dim cmd As SqlCommand = New SqlCommand(spGetMaxRecord, oMaxSocios)
        cmd.Parameters.Add("@resultado", 0)
        cmd.Parameters(0).Direction = ParameterDirection.Output
        cmd.ExecuteNonQuery()

        If cmd.Parameters(0).Value = 0 Then
            MsgBox("SI")
        Else
            MsgBox("NO")
        End If
algo asi...