Foros del Web » Programación para mayores de 30 ;) » .NET »

Object reference not set to an instance of an object

Estas en el tema de Object reference not set to an instance of an object en el foro de .NET en Foros del Web. Hola a todos. Estoy tratando de leer un archivo de excel para cargalo en grid. Estoy utilizando un dataset. el problema que estoy teniendo es ...
  #1 (permalink)  
Antiguo 30/06/2008, 11:29
 
Fecha de Ingreso: junio-2008
Mensajes: 1
Antigüedad: 15 años, 10 meses
Puntos: 0
Object reference not set to an instance of an object

Hola a todos.

Estoy tratando de leer un archivo de excel para cargalo en grid. Estoy utilizando un dataset.

el problema que estoy teniendo es que a la hora de hacer la conexión a excel me genera el error "Object reference not set to an instance of an object".

Adjunto código que estoy utilizando para leer el archivo.

///--------------------------------------------------------------------------------

Imports System.IO
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Diagnostics
Imports System.Configuration

Public Class OtrasFunciones

Shared Function LeerArchivoExcelGrid(ByVal Ruta As String, ByVal NombreHoja As String) As DataSet
Try
If File.Exists(Ruta) Then
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Ruta & ";Extended Properties=""Excel 8.0;HDR=Yes;"""
Dim objConn As OleDbConnection
Dim sql As String
Dim objDs As New DataSet

sql = "SELECT * FROM [" & NombreHoja & "$]"

Dim objCommand As New OleDbCommand(sql, objConn)
Dim objAdapter As New OleDbDataAdapter(objCommand)

objAdapter.Fill(objDs)

objConn.Close()
Return objDs 'Enlazado exitoso!
End If
Catch ex As Exception
End Try
End Function
End Class


si me pueden ayudar, se los agradecería muchísimo.

Gracias.

Yamil.
  #2 (permalink)  
Antiguo 30/06/2008, 11:52
Avatar de Peterpay
Colaborador
 
Fecha de Ingreso: septiembre-2007
Ubicación: San Francisco, United States
Mensajes: 3.858
Antigüedad: 16 años, 8 meses
Puntos: 87
Respuesta: Object reference not set to an instance of an object

no estas inicializando tu objConn
__________________
Curso WF4
http://cursos.gurudotnet.com/ DF
Aprende HTML5
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:42.