Hi, I have a very regular problem with MS Access showing random results when being written to from Visual Studio 2008. It happens on all computers including the development machine, using Vista or XP, VS 2005 or VS 2008.
Is there a VB.Net flush command I can use before reading the data ?.
I write data to a table and then immediately go to read that data.
I can make it work if I wait up to 3 seconds before I read the data after a write, using a sleep command. Unfortunately 3 seconds is way too long.
Are there any known problems with writing data to MSAccess 2003 from .Net, using VS 2008, VB.
Another weird things that happens is that only half the data is there if I write to an Access table and then go to read it immediately. Sometimes the data's there, sometimes not, with the exact same code and data. Sometimes the whole table fills with the data from the first record. This is happening throughout my code. Anywhere there's data being written to Access there's a problem if I go to read it immediately after.
Sometimes the Access table is blank, even though data has been written to it, and then on a second run of the exact same code it comes good, or gets half the data or every record is a duplicate of the first record.
The code is good, so it's not a coding problem, and I can run the exact same code and get good results. So it's definitely an intermittent problem.
I appreciate any help I can get with this.
I run all my access writes through the same code. The part of the code that writes the data is "command1.ExecuteNonQuery()". Whether I read the data from a datatable or as a merged word document, I still get the same problems. So I'm guessing that there's a problem with writing the data.
Public Sub ExecuteCommand(ByVal DataTableName As String, ByVal sqlString As String, ByRef LocalSQL As LocalSQL)
Try
Do Until SQLprocessingLocal = False
System.Windows.Forms.Application.DoEvents()
Loop
SQLprocessingLocal = True
dt = New DataTable
Dim command1 As OleDb.OleDbCommand = New OleDb.OleDbCommand(sqlString, oConnLocal)
adapter1 = New OleDbDataAdapter(command1)
Select Case DataTableName
Case "dtLocalPayments"
dtLocalPayments = New DataTable
adapter1.Fill(dtLocalPayments)
Case "dtTemp"
dtTemp = New DataTable
adapter1.Fill(dtTemp)
Case "dtDGV"
dtDGV = New DataTable
adapter1.Fill(dtDGV)
Case Else
Try
command1.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
SQLprocessingLocal = False
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
SQLprocessingLocal = False
Exit Sub
End Try
End Select
Catch ex As Exception
MsgBox("Error when doing an ExecuteCommand, call Tech Support")
SQLprocessingLocal = False
End Try
Debug.Print(sqlString)
SQLprocessingLocal = False
End Sub