Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/06/2008, 11:29
yquesada
 
Fecha de Ingreso: junio-2008
Mensajes: 1
Antigüedad: 16 años, 8 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.