Update Time in MSAccess / VB
Hi,
what is the best way to know when Access has finally executed a command sent to it by VB.Net ?
For instance, please review the following example:
Code:
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim strNewName As String = InputBox("Please Enter The New Packages's Name:", "New Package", , Me.Left, Me.Top)
If Trim(strNewName) <> "" Then
PackageMasterInsert(strNewName)
grdPackageItems.DataSource = Nothing
LoadPackageMaster(lstPackages)
End If
End Sub
Public Function PackageMasterInsert(ByVal NewName As String)
Dim conDB As New OleDb.OleDbConnection()
conDB = ConnectToDatabase()
Dim strSQLStm As String
Dim intRowsAffected As Integer
strSQLStm = "INSERT INTO tbl_PackageMaster (pkg_Name, pkg_Description) " & _
"VALUES ('" & NewName & "', '" & " " & "')"
Debug.WriteLine(strSQLStm)
Dim cmdInsert As New OleDb.OleDbCommand(strSQLStm, conDB)
intRowsAffected = cmdInsert.ExecuteNonQuery()
End Function
Public Function LoadPackageMaster(ByVal objPackages As Object)
Dim conDB As New OleDb.OleDbConnection()
conDB = ConnectToDatabase()
Dim strSQLStm As String = "SELECT * " & _
"FROM tbl_PackageMaster " & _
"ORDER BY pkg_Name"
Dim cmdPkg As New OleDb.OleDbCommand(strSQLStm, conDB)
Dim datPkg As OleDb.OleDbDataReader
objPackages.Items.Clear()
datPkg = cmdPkg.ExecuteReader
Do Until datPkg.Read = False
objPackages.Items.Add(New ListItem(datPkg("pkg_Name"), datPkg("pkg_ID")))
Loop
datPkg.Close()
End Function
What happens in 99% of the times i run this, is that the Loading of the Packages takes place before the insert of the new package has finished. Hence, when the list box is reloaded, the new package is not there.
If put in a timer and say wait for 3-5 seconds, then the next package is there.
This is happening on a PC with Ado.Net to Access 2K and all files are on my local drive.
Any suggestions?
cheers.