I am new to sql and vb.
I have the following code that works fine for MS SQL EXPRESS.
If cboServer.Text = "MS SQL Express" Then
Dim sqlBulk As New SqlBulkCopy(sCONN)
sqlBulk.BulkCopyTimeout = 500
sqlBulk.DestinationTableName = sTable
sqlBulk.WriteToServer(dReader)
End If
However I am not trying to write the data into MySQL due to the data limitations of MS SQL.
Here is what I have, But I know it is wrong.
If cboServer.Text = "MySQL" Then
Dim MyConn As New MySql.Data.MySqlClient.MySqlConnection
MyConn.ConnectionString = sCONN
Dim mysqlBulk As New MySql.Data.MySqlClient.MySqlBulkLoader(MyConn)
mysqlBulk.TableName = sTable
mysqlBulk.FileName = sFilename
mysqlBulk.Load()
End If
Below is the full mod.
Private Sub ImportFromExcel(ByVal sFilename As String, ByVal sTable As String)
Try
Dim excelConnectionString As String = String.Empty
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sFilename & ";Extended Properties=Excel 12.0;Persist Security Info=False"
Dim excelConnection As New OleDbConnection(excelConnectionString)
Dim cmd As New OleDbCommand("Select * from [" & sTable & "$]", excelConnection)
excelConnection.Open()
Dim dReader As OleDbDataReader
dReader = cmd.ExecuteReader()
If cboServer.Text = "MS SQL Express" Then
Dim sqlBulk As New SqlBulkCopy(sCONN)
sqlBulk.BulkCopyTimeout = 500
sqlBulk.DestinationTableName = sTable
sqlBulk.WriteToServer(dReader)
End If
If cboServer.Text = "MySQL" Then
Dim MyConn As New MySql.Data.MySqlClient.MySqlConnection
MyConn.ConnectionString = sCONN
Dim mysqlBulk As New MySql.Data.MySqlClient.MySqlBulkLoader(MyConn)
mysqlBulk.TableName = sTable
mysqlBulk.FileName = sFilename
mysqlBulk.Load()
End If
lstError.Items.Clear()
lstError.Items.Add(Microsoft.VisualBasic.Right(sFilename, 35) & " " & sTable)
excelConnection.Close()
Catch ex As Exception
lstError.Items.Add("Error Reading " & sFilename & " " & sTable)
lstError.Items.Add(Err.Description)
lstError.Items.Add("")
Exit Sub
End Try
End Sub
How do I get the MySQL part to load the data?