Foros del Web » Programando para Internet » ASPX (.net) »

Leer excel y guardar datos en tablas en sql server 2005.

Estas en el tema de Leer excel y guardar datos en tablas en sql server 2005. en el foro de ASPX (.net) en Foros del Web. Salu2 estoy haicendo una aplicación web para leer los datos de una hoja de excel y guardarlos en uns tabla en sql. En el evento ...
  #1 (permalink)  
Antiguo 04/03/2008, 13:19
 
Fecha de Ingreso: junio-2007
Mensajes: 253
Antigüedad: 16 años, 10 meses
Puntos: 0
Pregunta Leer excel y guardar datos en tablas en sql server 2005.

Salu2 estoy haicendo una aplicación web para leer los datos de una hoja de excel y guardarlos en uns tabla en sql.

En el evento click del button programo la lectura del excel:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim bodega_hoja As String = "BODEGA"
Dim appExcel As Object
Dim Fila As Integer = 2
Dim cod As Integer
Dim bloq As String
Dim num As String
Dim dim As Integer

appExcel = CreateObject("Excel.Application")
Dim mstrRutaOrigen As String = Path.GetFullPath(FileUpload1.PostedFile.FileName.T oString)
Dim bodega_libro As String = mstrRutaOrigen
appExcel.Workbooks.open(filename:=bodega_libro)
cn.Open()

With appExcel.Sheets(bodega_hoja)
.Select()
While .Cells(Fila, 1).Value > 0
cod = .Cells(Fila, 1).Value
bloq = .Cells(Fila, 2).Value
num = .Cells(Fila, 3).Value
dim = .Cells(Fila, 4).Value
insertar_datos_bodega(cod, bloq, num, dim)
End If
Fila = Fila + 1
End While
End With
End Sub

y con este procedimiento supuestamente deberia insertar los datos en la tabla.

Private Sub insertar_datos_bodega(ByVal cod_usuario As Integer, ByVal bod_bloq As String, ByVal bod_num As String, ByVal bod_dim As Integer)
With cmd
.Connection = cn
.CommandType = CommandType.Text
.CommandText = "INSERT INTO BODEGA ([id], [bloque], [numero], [dimension]) VALUES (" & cod & ", '" & bloq & "', '" & num & "', " & dim & ")"
.ExecuteNonQuery()
Label2.Text = "¡Regristos actualizados con éxito!"
End With
End Sub

Pero al ejecutarlo me da el siguiente error:

Server Error in '/excel' Application.
--------------------------------------------------------------------------------

Cannot create ActiveX component.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Cannot create ActiveX component.

Source Error:

Line 42: appExcel = CreateObject("Excel.Application")
Line 43: Dim mstrRutaOrigen As String = Path.GetFullPath(FileUpload1.PostedFile.FileName.T oString)
Line 44: Dim bodega_libro As String = mstrRutaOrigen

Ya he hecho varias tips que me han recomendado como ingresar a herramientas administrativas del panel de control y escoger componentes de Servicios, luego en DCOM Config escoger Microsoft Excel Application y en sus propiedades en la pestaña de seguridad agregar el usuario ASP.NET y varios más pero nada funciona me sigue saliendo ese error.

Por favor alguna ayuda o si hay alguna otra forma de hacer lo que necesito se los agradecería muchisimo que me lo hagan saber.
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 05:02.