Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/01/2008, 18:29
xmxsicl
 
Fecha de Ingreso: enero-2008
Mensajes: 5
Antigüedad: 17 años, 1 mes
Puntos: 0
Mostrar mensaje de error cuando no hay nada en la Base de datos!

Hola

Espero que alguien pueda ayudarme. Tengo un Sub en VB.NET donde cargo los datos en un DataAdapter y luego los paso a un dataSet. Cuando pongo un nombre de usuario que no esta en la base de datos, el dataset esta vacío y me sale el error "There is no row at position 0".

No sé como puedo evitar esto. Traté con un catch ex as sqlException, pero mas bien lo que hace es saltarselo y seguir con las siguientes instrucciones. Espero que alguien pueda ayudarme

Alguien que me ayude será sumamente agradecido

Aca les pongo mi codigo:

************************************************** *********

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As ProcedimientosGenerales = New ProcedimientosGenerales

' Se abre la base de datos
CadenaConexion = f.AbrirBaseDatos(CadenaConexion)
conexion = f.ConexionBaseDatos(CadenaConexion, conexion)
comando = New SqlCommand(CadenaConexion, conexion)

' Se crea un SqlDataAdapter para la tabla EMPLOYEE.
Dim DatosEmpleado As SqlDataAdapter = New SqlDataAdapter()

' Se hace una tabla “table” que mapee los datos de EMPLOYEE.
DatosEmpleado.TableMappings.Add("Table", "Employee")

Dim ComandoEMPLEADO As SqlCommand = New SqlCommand( _
"SELECT [USER].MUD_ID, [USER].STRFIRSTNAME, [USER].STRLASTNAME, DEPARTMENT.STRDEP_NAME, DEPARTMENT.STRSUPERVISOR, [USER].AVAILABLEDAYS, [USER].TAKENDAYS FROM EMPLOYEE INNER JOIN [USER] ON EMPLOYEE.US_CODE = [USER].MUD_ID INNER JOIN LINE_MANAGER ON EMPLOYEE.US_CODE = LINE_MANAGER.EMP_US_CODE AND [USER].MUD_ID = LINE_MANAGER.US_CODE INNER JOIN DEPARTMENT ON LINE_MANAGER.DEP_CODE = DEPARTMENT.CODE WHERE [user].mud_id = '" & txtusername.Text & "'", conexion)

' Se crea un SqlCommand para recuperar la info de EMPLOYEE.
ComandoEMPLEADO.CommandType = CommandType.Text

' Se incorpora el SelectCommand del SqlDataAdapter.
DatosEmpleado.SelectCommand = ComandoEMPLEADO

' Se llena el DataSet.

Dim DS As DataSet = New DataSet("Employee")
DatosEmpleado.Fill(DS)

' QUE HAGO ACA!???? Aca es donde me aparece el error
If DS.Tables("Employee").Rows(0)(0).ToString = "" Then
MensajeError.Text = "ERROR. Usuario no se encuentra en Base de Datos"
Else
' Visualiza los datos en los textboxes

txtNombreEmpleado.Text = ((DS.Tables("Employee").Rows(0)(1).ToString) + " " + (DS.Tables("Employee").Rows(0)(2).ToString))
txtDepartamento.Text = DS.Tables("Employee").Rows(0)(3).ToString
txtjefeinmediato.Text = DS.Tables("Employee").Rows(0)(4).ToString
txtdiastomados.Text = DS.Tables("Employee").Rows(0)(5).ToString
txtdiasdisponibles.Text = DS.Tables("Employee").Rows(0)(6).ToString

' Visualiza los ddatos en un DataGridView A MODO DE PRUEBA

DataGrid1.DataSource = DS.Tables("Employee")
End If
conexion = f.Cerrarbasedatos(conexion)

End Sub

************************************************** *********

Lo de el SqlCommand, eso me funciona, es que lo puse en linea continua, no dividí la cadena pero si me funciona.

Gracias por toda la ayuda que me puedan brindar.