Hello, so my mini project loops through all emails in a specific Outlook Folder, saves all zipped mdb attachments and unzips them.
Now I need to copy the data that are in a table (which is the same for all mdbs in the zipped attachments) and save them to a temporary table in my master mdb. Once all data has been saved to the temporary table in my master db, it will now check for duplicates (based on the checker column) in the main table in my master db. If there are duplicates, the duplicates found in the main table will then be copied to a history table. Once copied to the history table, the duplicates will be removed from the main table. And then the contents of the temporary table will be saved to the main table.
In other words I need to consolidate the data from all mdbs to my master mdb without duplicates. All the databases are password-protected.
Any ideas? I know how to do the segregation of the duplicates from non duplicates and the rest of the steps. I just don't know how to consolidate all data from all the other databases to my temporary table in my master db.
Here's my code so far:
Since I need to unzip the files that were downloaded from Outlook, I added the select from databases from Outlook and insert into master db in the unzipping code. But the thing is, it only inserts data if there's just one database in the folder. If there's more than one database, it won't do anything.
What I do is I rename the databases that have been unzipped to SLA.mdb so my connection string will be fixed.
What am I doing wrong :(
Now I need to copy the data that are in a table (which is the same for all mdbs in the zipped attachments) and save them to a temporary table in my master mdb. Once all data has been saved to the temporary table in my master db, it will now check for duplicates (based on the checker column) in the main table in my master db. If there are duplicates, the duplicates found in the main table will then be copied to a history table. Once copied to the history table, the duplicates will be removed from the main table. And then the contents of the temporary table will be saved to the main table.
In other words I need to consolidate the data from all mdbs to my master mdb without duplicates. All the databases are password-protected.
Any ideas? I know how to do the segregation of the duplicates from non duplicates and the rest of the steps. I just don't know how to consolidate all data from all the other databases to my temporary table in my master db.
Here's my code so far:
Code:
Dim con1 As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source= path\SLA.mdb;Jet OLEDB:Database Password=")
Dim con2 As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source= path\SLA.mdb;Jet OLEDB:Database Password=")
Dim AQuery As New System.Data.OleDb.OleDbCommand
Dim AAdapter As OleDb.OleDbDataAdapter
Sub unpackAll(pat As String)
If Not Directory.Exists(pat) Then Exit Sub
For Each zfn In Directory.GetFiles(pat, "*.zip")
Try
ZipFile.ExtractToDirectory(zfn, pat)
'Create the data adapter with a SelectCommand using the first connection.
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM tblDailyData", con1)
'Add the InsertCommand with the second connection.
da.InsertCommand = New OleDb.OleDbCommand("INSERT INTO tblTemp (UploaderEID, DateUploaded, DealName, Industry, Workstream, Tower, DateOfData, WeekBeginning, Metric, MetricValue, Format, Multiplier, MultiplierValue, Waived, checker, CurrentUploader, DateTimeUploaded, RandomID)
VALUES (@UploaderEID, @DateUploaded, @DealName, @Industry, @Workstream, @Tower, @DateOfData, @WeekBeginning, @Metric, @MetricValue, @Format, @Multiplier, @MultiplierValue, @Waived, @checker, @CurrentUploader, @DateTimeUploaded, @RandomID)", con2)
'Add the insert parameters.
da.InsertCommand.Parameters.Add("@UploaderEID", OleDb.OleDbType.VarChar, 50, "UploaderEID")
da.InsertCommand.Parameters.Add("@DateUploaded", OleDb.OleDbType.Date, 50, "DateUploaded")
da.InsertCommand.Parameters.Add("@DealName", OleDb.OleDbType.VarChar, 50, "DealName")
da.InsertCommand.Parameters.Add("@Industry", OleDb.OleDbType.VarChar, 50, "Industry")
da.InsertCommand.Parameters.Add("@Workstream", OleDb.OleDbType.VarChar, 50, "Workstream")
da.InsertCommand.Parameters.Add("@Tower", OleDb.OleDbType.VarChar, 50, "Tower")
da.InsertCommand.Parameters.Add("@DateOfData", OleDb.OleDbType.Date, 50, "DateOfData")
da.InsertCommand.Parameters.Add("@WeekBeginning", OleDb.OleDbType.Date, 50, "WeekBeginning")
da.InsertCommand.Parameters.Add("@Metric", OleDb.OleDbType.VarChar, 50, "Metric")
da.InsertCommand.Parameters.Add("@MetricValue", OleDb.OleDbType.VarChar, 50, "MetricValue")
da.InsertCommand.Parameters.Add("@Format", OleDb.OleDbType.VarChar, 50, "Format")
da.InsertCommand.Parameters.Add("@Multiplier", OleDb.OleDbType.VarChar, 50, "Multiplier")
da.InsertCommand.Parameters.Add("@MultiplierValue", OleDb.OleDbType.VarChar, 50, "MultiplierValue")
da.InsertCommand.Parameters.Add("@Waived", OleDb.OleDbType.VarChar, 50, "Waived")
da.InsertCommand.Parameters.Add("@checker", OleDb.OleDbType.VarChar, 100, "checker")
da.InsertCommand.Parameters.Add("@CurrentUploader", OleDb.OleDbType.VarChar, 40).Value = Environment.UserName
da.InsertCommand.Parameters.Add("@DateTimeUploaded", OleDb.OleDbType.Date, 40).Value = DateTime.Now
da.InsertCommand.Parameters.Add("@RandomID", OleDb.OleDbType.VarChar, 100, "RandomID")
'Keep the records ina state where they can be inserted into the destination table.
da.AcceptChangesDuringFill = False
Dim dt As New DataTable
'Get the data from the source database.
da.Fill(dt)
'Save the data to the destination database.
da.Update(dt)
Catch ex As Exception
End Try
Next
File.Delete("path\SLA.mdb")
End Sub
What I do is I rename the databases that have been unzipped to SLA.mdb so my connection string will be fixed.
What am I doing wrong :(