我有一个程序可以删除我的 Access2010 数据库中任何早于某个日期的数据,然后压缩数据库。程序的删除部分工作正常,但是当我尝试在之后立即压缩它时出现错误“无效参数” 。这是我的代码的样子:
'Deleting anything older than chosen before databse is compacted.
Dim DateA As Date = Date.Now
Dim DateB As String
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Fortedb.accdb"
Dim ParentCNN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Fortedb.accdb"
Dim CloneCNN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Temp.accdb"
Dim cnn As New OleDbConnection(ConnString)
Dim sql As String
'Formatting the date to make it 7 days into the past.
DateB = Format(DateA.AddDays(ApplicationPropertiesWindow.DeleteFilebox.SelectedIndex + 1), "MM/dd/yy")
cnn.Open()
'Delete everything from b_forte where proddate is less than date - chosen time.
sql = "DELETE * FROM b_forte WHERE ProdDate < #" & DateB & "#"
Dim Command = New OleDb.OleDbCommand(sql, cnn)
Command.ExecuteNonQuery()
cnn.Close()
'Compacting the databse
Try
Dim JrO As New JRO.JetEngine
cnn.Open()
JrO.CompactDatabase(ParentCNN, CloneCNN)
If System.IO.File.Exists("C:\Forte\Temp.accdb") Then
System.IO.File.Delete("C:\Forte\Fortedb.accdb")
Rename("C:\Forte\Temp.accdb", "C:\Forte\Fortedb.accdb")
Logging("Database compacted.")
cnn.Close()
End If
Catch ex As Exception
MainTextBox.AppendText(Environment.NewLine & "Database Compression Failure :" & vbCr & ex.Message)
End Try
我正在使用 vb.net 2010 并在数据库上没有密码访问 2010。