ProfessionalGold
New member
- Joined
- Dec 13, 2011
- Messages
- 2
- Programming Experience
- Beginner
Hello,
Please help:
I am trying to convert HyperFileSqlDatabase to mdb database using this code:
****************************************
Code:
**************************************
The problem is that the conversion is very slow.
Any suggestions please.
Please help:
I am trying to convert HyperFileSqlDatabase to mdb database using this code:
****************************************
Code:
VB.NET:
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports System.Text
Imports System.Data.SqlClient
Imports System.Data
Imports ADOX
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ADOXcatalog As New ADOX.Catalog
Dim ADOXtable As New ADOX.Table
If System.IO.File.Exists("d:\1.mdb") = True Then
System.IO.File.Delete("d:\1.mdb")
End If
If System.IO.File.Exists("d:\1.ldb") = True Then
System.IO.File.Delete("d:\1.ldb")
End If
If System.IO.File.Exists("d:\1.txt") = True Then
System.IO.File.Delete("d:\1.txt")
End If
ADOXcatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "d:\1.mdb")
ADOXtable.Name = "Employees"
ADOXtable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
ADOXtable.Columns.Append("Name", ADOX.DataTypeEnum.adLongVarWChar)
ADOXtable.Columns.Append("Info1", ADOX.DataTypeEnum.adLongVarWChar)
ADOXtable.Columns.Append("Info2", ADOX.DataTypeEnum.adLongVarWChar)
ADOXtable.Columns.Append("Info3", ADOX.DataTypeEnum.adLongVarWChar)
ADOXtable.Columns.Append("Info4", ADOX.DataTypeEnum.adLongVarWChar)
ADOXtable.Columns.Append("Image", ADOX.DataTypeEnum.adLongVarWChar)
ADOXcatalog.Tables.Append(ADOXtable)
ADOXtable = Nothing
ADOXcatalog = Nothing
Dim ConnectionStr1 As String = "Provider=PCSoft.HFSQL;Initial Catalog="D:\"
Dim ConnectionStr2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "d:\1.mdb"
Try
Dim Connection1 As OleDbConnection = New OleDbConnection(ConnectionStr1)
Dim Connection2 As OleDbConnection = New OleDbConnection(ConnectionStr2)
Connection1.Open()
Connection2.Open()
Dim OleDbCmd1 As OleDbCommand = New OleDbCommand("SELECT * from Employees", Connection1)
Dim OleDbRd1 As OleDbDataReader = OleDbCmd1.ExecuteReader
Dim ByteImage() As Byte
Dim Name, Info1, Info2, Info3, Info4,Image As String
Dim ID As Integer
'Dim i As Integer = 0
While OleDbRd1.Read()
ID = OleDbRd1(0)
Name= OleDbRd1(1)
Name= Name.Replace("'", "''")
Info1= OleDbRd1(2)
Info1= Info1.Replace("'", "''")
Info2= OleDbRd1(3)
Info2= Info2.Replace("'", "''")
Info3= OleDbRd1(4)
Info3= Info3.Replace("'", "''")
ByteImage= OleDbRd1(5)
Image = Encoding.ASCII.GetString(ByteImage)
Image= Image.Replace("'", "''")
Dim OleDbCmd2 As OleDbCommand = New OleDbCommand("INSERT INTO Employees(ID,Name,Info1,Info2,Info3,Image) VALUES (@ID,@Name,@Info1,@Info2,@Info3,Image)", Connection2)
OleDbCmd2.Parameters.AddWithValue("@ID", ID)
OleDbCmd2.Parameters.AddWithValue("@Name", Name)
OleDbCmd2.Parameters.AddWithValue("@Info1", Info1)
OleDbCmd2.Parameters.AddWithValue("@Info2", Info2)
OleDbCmd2.Parameters.AddWithValue("@Info3", Info3)
OleDbCmd2.Parameters.AddWithValue("@Q4", strQ4)
OleDbCmd2.Parameters.AddWithValue("@Q5", strQ5)
OleDbCmd2.Parameters.AddWithValue("@Image", Image)
OleDbCmd2.ExecuteNonQuery()
'i += 1
'Dim ObjWriter As New System.IO.StreamWriter("D:\1.txt", True)
'ObjWriter.WriteLine(i)
'ObjWriter.Close()
'Label1.Text = "file:" & i & " / 775"
'Application.DoEvents()
End While
OleDbRd1.Close()
OleDbCmd1.Dispose()
Connection1.Close()
Connection2.Close()
Catch ex As OleDbException
MsgBox(ex.ToString)
End Try
MsgBox("ok")
End Sub
End Class
The problem is that the conversion is very slow.
Any suggestions please.