Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim con1 As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= '" & TextBoxDatabasePath.Text & "' ;Jet OLEDB:Database Password=cscfo13@em;")
Dim con2 As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ATSDatabase.accdb;Jet OLEDB:Database Password=cscfo13@ts;")
'Create the data adapter with a SelectCommand using the first connection.
Dim da As New OleDb.OleDbDataAdapter("SELECT ID, Fullname, FirstName, MiddleName, LastName, Extension, ControlNo, Position, Itemno, FieldOffice, Gender, TeachingNonTeaching, Status, Nature, Effective_Date, DateReceived, Sector, Processor, DateProcessed, ActionOfficer, DateActed, Action, DateReleased, FullNameCN, remarks, encoded_by, released_by, datetime_processed, datetime_acted, Date_encoded, Date_Docs_Completed, Date_Elig_Verified, Date_file_retrieved, DateTime_file_retrieved, DateVerif_Elig_letter_created, DateTime_Processing, DateTime_Action, Verification_Source, FullnameDrec, noofdaysnewemprec, noofdaysupdtdexistrec, accreditation, dateissued, submissionstat FROM ATS ", con1)
'Add the InsertCommand with the second connection.
da.InsertCommand = New OleDb.OleDbCommand("INSERT INTO ATS (ID, Fullname, FirstName, MiddleName, LastName, Extension, ControlNo, Position, Itemno, FieldOffice, Gender, TeachingNonTeaching, Status, Nature, Effective_Date, DateReceived, Sector, Processor, DateProcessed, ActionOfficer, DateActed, Action, DateReleased, FullNameCN, remarks, encoded_by, released_by, datetime_processed, datetime_acted, Date_encoded, Date_Docs_Completed, Date_Elig_Verified, Date_file_retrieved, DateTime_file_retrieved, DateVerif_Elig_letter_created, DateTime_Processing, DateTime_Action, Verification_Source, FullnameDrec, noofdaysnewemprec, noofdaysupdtdexistrec, accreditation, dateissued, submissionstat) VALUES (@ID, @Fullname, @FirstName, @MiddleName, @LastName, @Extension, @ControlNo, @Position, @Itemno, @FieldOffice, @Gender, @TeachingNonTeaching, @Status, @Nature, @Effective_Date, @DateReceived, @Sector, @Processor, @DateProcessed, @ActionOfficer, @DateActed, @Action, @DateReleased, @FullNameCN, @remarks, @encoded_by, @released_by, @datetime_processed, @datetime_acted, @Date_encoded, @Date_Docs_Completed, @Date_Elig_Verified, @Date_file_retrieved, @DateTime_file_retrieved, @DateVerif_Elig_letter_created, @DateTime_Processing, @DateTime_Action, @Verification_Source, @FullnameDrec, @noofdaysnewemprec, @noofdaysupdtdexistrec, @accreditation, @dateissued, @submissionstat)", con2)
'Add the insert parameters.
da.InsertCommand.Parameters.Add("@ID", OleDb.OleDbType.Integer, 0, "ID")
da.InsertCommand.Parameters.Add("@Fullname", OleDb.OleDbType.VarChar, 50, "Fullname")
da.InsertCommand.Parameters.Add("@FirstName", OleDb.OleDbType.VarChar, 50, "FirstName")
da.InsertCommand.Parameters.Add("@MiddleName", OleDb.OleDbType.VarChar, 50, "MiddleName")
da.InsertCommand.Parameters.Add("@LastName", OleDb.OleDbType.VarChar, 50, "LastName")
da.InsertCommand.Parameters.Add("@Extension", OleDb.OleDbType.VarChar, 50, "Extension")
da.InsertCommand.Parameters.Add("@ControlNo", OleDb.OleDbType.VarChar, 200, "ControlNo")
da.InsertCommand.Parameters.Add("@Position", OleDb.OleDbType.VarChar, 200, "Position")
da.InsertCommand.Parameters.Add("@Itemno", OleDb.OleDbType.VarChar, 200, "Itemno")
da.InsertCommand.Parameters.Add("@FieldOffice", OleDb.OleDbType.VarChar, 100, "FieldOffice")
da.InsertCommand.Parameters.Add("@Gender", OleDb.OleDbType.VarChar, 50, "Gender")
da.InsertCommand.Parameters.Add("@TeachingNonTeaching", OleDb.OleDbType.VarChar, 50, "TeachingNonTeaching")
da.InsertCommand.Parameters.Add("@Status", OleDb.OleDbType.VarChar, 50, "Status")
da.InsertCommand.Parameters.Add("@Nature", OleDb.OleDbType.VarChar, 50, "Nature")
da.InsertCommand.Parameters.Add("@Effective_Date", OleDb.OleDbType.Date, 50, "Effective_Date")
da.InsertCommand.Parameters.Add("@DateReceived", OleDb.OleDbType.Date, 50, "DateReceived")
da.InsertCommand.Parameters.Add("@Sector", OleDb.OleDbType.VarChar, 50, "Sector")
da.InsertCommand.Parameters.Add("@Processor", OleDb.OleDbType.VarChar, 100, "Processor")
da.InsertCommand.Parameters.Add("@DateProcessed", OleDb.OleDbType.Date, 50, "DateProcessed")
da.InsertCommand.Parameters.Add("@ActionOfficer", OleDb.OleDbType.VarChar, 100, "ActionOfficer")
da.InsertCommand.Parameters.Add("@DateActed", OleDb.OleDbType.Date, 50, "DateActed")
da.InsertCommand.Parameters.Add("@Action", OleDb.OleDbType.VarChar, 50, "Action")
da.InsertCommand.Parameters.Add("@DateReleased", OleDb.OleDbType.Date, 50, "DateReleased")
da.InsertCommand.Parameters.Add("@FullNameCN", OleDb.OleDbType.VarChar, 200, "FullNameCN")
da.InsertCommand.Parameters.Add("@remarks", OleDb.OleDbType.VarChar, 300, "remarks")
da.InsertCommand.Parameters.Add("@encoded_by", OleDb.OleDbType.VarChar, 100, "encoded_by")
da.InsertCommand.Parameters.Add("@released_by", OleDb.OleDbType.VarChar, 100, "released_by")
da.InsertCommand.Parameters.Add("@datetime_processed", OleDb.OleDbType.Date, 50, "datetime_processed")
da.InsertCommand.Parameters.Add("@datetime_acted", OleDb.OleDbType.Date, 50, "datetime_acted")
da.InsertCommand.Parameters.Add("@Date_encoded", OleDb.OleDbType.Date, 50, "Date_encoded")
da.InsertCommand.Parameters.Add("@Date_Docs_Completed", OleDb.OleDbType.Date, 50, "Date_Docs_Completed")
da.InsertCommand.Parameters.Add("@Date_Elig_Verified", OleDb.OleDbType.Date, 50, "Date_Elig_Verified")
da.InsertCommand.Parameters.Add("@Date_file_retrieved", OleDb.OleDbType.Date, 50, "Date_file_retrieved")
da.InsertCommand.Parameters.Add("@DateTime_file_retrieved", OleDb.OleDbType.Date, 50, "DateTime_file_retrieved")
da.InsertCommand.Parameters.Add("@DateVerif_Elig_letter_created", OleDb.OleDbType.Date, 50, "DateVerif_Elig_letter_created")
da.InsertCommand.Parameters.Add("@DateTime_Processing", OleDb.OleDbType.Date, 50, "DateTime_Processing")
da.InsertCommand.Parameters.Add("@DateTime_Action", OleDb.OleDbType.Date, 50, "DateTime_Action")
da.InsertCommand.Parameters.Add("@Verification_Source", OleDb.OleDbType.Integer, 0, "Verification_Source")
da.InsertCommand.Parameters.Add("@FullnameDrec", OleDb.OleDbType.VarChar, 200, "FullnameDrec")
da.InsertCommand.Parameters.Add("@noofdaysnewemprec", OleDb.OleDbType.Integer, 50, "noofdaysnewemprec")
da.InsertCommand.Parameters.Add("@noofdaysupdtdexistrec", OleDb.OleDbType.Integer, 50, "noofdaysupdtdexistrec")
da.InsertCommand.Parameters.Add("@accreditation", OleDb.OleDbType.VarChar, 50, "accreditation")
da.InsertCommand.Parameters.Add("@dateissued", OleDb.OleDbType.Date, 50, "dateissued")
da.InsertCommand.Parameters.Add("@submissionstat", OleDb.OleDbType.VarChar, 50, "submissionstat")
'Keep the records in a 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)
MsgBox("Data Added!")
End Sub
我试图运行程序,然后单击按钮,代码不起作用。我想要的是将记录从一个数据库复制到另一个数据库。这是我得到的错误。
IErrorInfo.GetDescription因E_FAIL(0x80004005)而失败。
请帮帮我。