I run into a strange error.
When I close my application (created with vb2010), I copy all records from a mysql table to a local ms access database table.
The ms access table contains 2 tables (songs, email).
I want to copy the records from the online email table into the local database, but I got this strange error:
The instruction INSERT INTO contains a syntaxerror.
The strange thing is, that when I try to copy the songs table, it works perfect, so there is something wrong, but what.
Here is the code I use:
Hope you guys can pinpoint the problem.
Thanks.
When I close my application (created with vb2010), I copy all records from a mysql table to a local ms access database table.
The ms access table contains 2 tables (songs, email).
I want to copy the records from the online email table into the local database, but I got this strange error:
The instruction INSERT INTO contains a syntaxerror.
The strange thing is, that when I try to copy the songs table, it works perfect, so there is something wrong, but what.
Here is the code I use:
VB.NET:
Private Sub SplashScreen2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If My.Computer.Network.Ping("195.128.174.38") Then
Dim dt As New DataSet()
Try
'Get Data into DataTable from MySQL Server database
Using cnn As New MySqlConnection("Server=host;Database=db;Uid=user;Pwd=pw")
Dim cmdSelect As MySqlCommand = New MySqlCommand("Select * From email")
cmdSelect.Connection = cnn
Dim ad As New MySqlDataAdapter(cmdSelect)
ad.AcceptChangesDuringFill = False
ad.Fill(dt)
End Using
Try
ProgressBarX1.Maximum = dt.Tables(0).Rows.Count
DeleteRecords()
Try
'Insert Data from DataTable into Access database
Using cnn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= |DataDirectory|\songlisteditor.accdb")
Dim cmdSelect As OleDbCommand = New OleDbCommand("Select * From email")
cmdSelect.Connection = cnn
Dim ad As New OleDbDataAdapter(cmdSelect)
Dim cmdBuilder As New OleDbCommandBuilder(ad)
Dim cmd As OleDbCommand = cmdBuilder.GetInsertCommand()
cmd.Connection = cnn
For Each row As DataRow In dt.Tables(0).Rows
ad.InsertCommand = cmd
ProgressBarX1.Value += 1
Next
ad.Update(dt)
End Using
Catch ex3 As Exception
MessageBox.Show(ex3.Message)
End Try
Catch ex2 As Exception
MessageBox.Show(ex2.Message)
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
MessageBox.Show("No connection with database available!", "Addressbook", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End sub
Private Sub DeleteRecords()
Dim cnn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= |DataDirectory|\songlisteditor.accdb")
Dim cmd As New OleDbCommand
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = "DELETE FROM email"
Using cnn
cnn.Open()
cmd.ExecuteNonQuery()
End Using
End Sub
Hope you guys can pinpoint the problem.
Thanks.