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 New OleDbConnection Dim xls_cmd As New OleDbCommand Dim xls_reader As New OleDbDataAdapter Dim mysql_conn As New MySqlConnection Dim mysql_comando As New MySqlCommand Dim xls_sql, mysql_connstring, insert As String 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 Dim strExtension As String = "" Dim nombreXls As String Dim m_Excel As Microsoft.Office.Interop.Excel.Application nombreXls = Path.GetFileName(xlsx) strExtension = Path.GetExtension(xlsx) If strExtension = ".xls" Or strExtension = ".xlsx" Then 'MsgBox("es un archivo excel") If (File.Exists(xlsx)) Then xls_cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlsx + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=0'" 'xls_cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" + xlsx + ";Extended Properties='Excel 12.0;HDR=YES'" Using xls_cn m_Excel.Workbooks.Open(xlsx) xls_cn.Open() xls_cmd.CommandText = "SELECT * FROM [Hoja1$]" xls_cmd.Connection = xls_cn xls_reader.SelectCommand = xls_cmd [B]'quiero aquí obtener los datos del excel ya que algunos de ellos luego tengo que guardarlos en una base de datos[/B] End Using 'Eliminamos la instancia de Excel de memoria If Not m_Excel Is Nothing Then m_Excel.Quit() m_Excel = Nothing End If End If Else Exit Sub End If End If Catch ex As Exception End Try End Sub