Alguien me puede ayudar?
Código vb.net:
Ver original
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim xls_cn As OleDbConnection Dim xls_cmd As New OleDbCommand Dim xls_reader As New OleDbDataAdapter Dim xls_ds As New DataSet Dim mysql_conn As New MySqlConnection Dim mysql_comando As New MySqlCommand Dim mysql_connstring, insert, nombreXls, fecha, factura, tTrafico, telefono, extension, cantidad, bruto, neto, facturado As String Dim strExtension As String = "" Dim m_Excel As Microsoft.Office.Interop.Excel.Application Dim total, i, notificado As Integer If Me.servidor.Text = "" Or Me.usuario.Text = "" Or Me.password.Text = "" Or Me.bbdd.Text = "" Then Exit Sub End If Try If xlsx = "" Then Exit Sub Else 'obtener el nombre del archivo nombreXls = Path.GetFileName(xlsx) 'obtener la extension del archivo strExtension = Path.GetExtension(xlsx) If strExtension = ".xls" Or strExtension = ".xlsx" Then 'MsgBox("es un archivo excel") If (File.Exists(xlsx)) Then xls_cn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlsx + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=0'") m_Excel.Workbooks.Open(xlsx) Dim dt As New DataTable("Datos") Using xls_cn xls_cn.Open() xls_cmd.CommandText = "SELECT * FROM [Hoja1$]" xls_cmd.Connection = xls_cn xls_reader.SelectCommand = xls_cmd 'contar candidad de filas del excel total = m_Excel.Range("a1").CurrentRegion.Rows.Count 'Guardamos los datos en el DataTable Dim da As New OleDbDataAdapter(xls_cmd) da.Fill(dt) For i = 0 To total - 2 fecha = dt.Rows(i).Item(2) factura = dt.Rows(i).Item(3) telefono = dt.Rows(i).Item(4).ToString extension = dt.Rows(i).Item(5).ToString tTrafico = dt.Rows(i).Item(6) cantidad = dt.Rows(i).Item(8).ToString bruto = dt.Rows(i).Item(10).ToString neto = dt.Rows(i).Item(13).ToString facturado = dt.Rows(i).Item(16).ToString notificado = "0" '--------------------------------------------------------------------------------------------------------------------- 'GUARDAR TODO EN SSIICONSUMOS Try mysql_connstring = "server=" + Me.servidor.Text + ";" _ & "uid=" + Me.usuario.Text + ";" _ & "pwd=" + Me.password.Text + ";" _ & "database=" + Me.bbdd.Text + ";" mysql_conn.ConnectionString = mysql_connstring mysql_conn.Open() mysql_comando.Connection = mysql_conn Catch ex As Exception End Try insert = "INSERT INTO detalle4(factura, telefono, extension, tipo_trafico, fecha, cantidad, bruto, neto, facturar, notificado) VALUES ('" & factura & "','" & telefono & "','" & extension & "','" & tTrafico & "','" & fecha & "','" & cantidad & "','" & bruto & "','" & neto & "','" & facturado & "','" & notificado & "')" mysql_comando.CommandText = insert Try mysql_comando.ExecuteNonQuery() Catch ex As Exception 'MsgBox("Error bbdd" & Chr(13) & Chr(13) & ex.Message) End Try Next End Using End If Else Exit Sub End If End If Catch ex As Exception End Try 'Cerramos la conexión 'Eliminamos la instancia de Excel de memoria If Not m_Excel Is Nothing Then nombreXls = Nothing m_Excel.Application.Quit() 'm_Excel.Quit() m_Excel = Nothing End If End Sub