F
fniles
I am using VB.NET 2005 and Access database.
My program uses a timer that kicks in every 1 min to read from a database
and copy the dataset table to a datatable.
This database is in a class called clsStat.vb.
Then I pass this class to a thread.
Each thread will call a function inside the clsStat.vb to do a "Select" of
the datatable.
Every day around the same time this function that does the select of the
databale gets errors like so:
There is no row at position 563.
There is no row at position 571.
There is no row at position 601.
Eventually, this function gets the error "DataTable internal index is
corrupted: '5'. "
I read that "The DataTable is not designed to be thread safe for
modifications for performance reasons.
Modifications include selecting rows using Select method on DataTable
because this can modify the datatable by creating a new index on it.
The article says to "resolve this you need to use the lock statement around
all modifications to DataTable."
What is a lock statement and how can I use it ?
What causes the errors "There is no row at position 601." and "DataTable
internal index is corrupted: '5'. " ,
and how to fix it ? Thank you
The timer code in the main program:
Private Sub TimerStat_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TimerStat.Tick
dim m_da As OleDb.OleDbDataAdapter
dim m_cmd As OleDb.OleDbCommand
Dim m_ds As DataSet
m_cmd = New OleDb.OleDbCommand
With m_cmd
.Connection = adoConOLE
.CommandText = "select a,b from stat"
End With
m_da = New OleDb.OleDbDataAdapter
m_ds = New DataSet
m_da.Fill(m_ds)
m_clsStat = New clsStat
m_clsStat.CopyStatTable(m_ds)
If Not (BestSession) Is Nothing Then 'this is my thread
BestSession.oclsStat = m_clsStat
End If
rs.CloseRS()
rs = Nothing
end sub
This is the clsStat.vb code:
Dim m_dtStat As DataTable
Public Sub CopyStatTable(ByVal m_ds As dataset)
m_dtStat = m_ds.Tables(0).Copy()
end sub
Public Function SelectStat(ByVal Account As String, ByVal sCol As String) As
DataRow()
SelectStat = m_dtStat.Select(sCol & "='" & Trim(Account) & "'") '--> error
here
end sub
My program uses a timer that kicks in every 1 min to read from a database
and copy the dataset table to a datatable.
This database is in a class called clsStat.vb.
Then I pass this class to a thread.
Each thread will call a function inside the clsStat.vb to do a "Select" of
the datatable.
Every day around the same time this function that does the select of the
databale gets errors like so:
There is no row at position 563.
There is no row at position 571.
There is no row at position 601.
Eventually, this function gets the error "DataTable internal index is
corrupted: '5'. "
I read that "The DataTable is not designed to be thread safe for
modifications for performance reasons.
Modifications include selecting rows using Select method on DataTable
because this can modify the datatable by creating a new index on it.
The article says to "resolve this you need to use the lock statement around
all modifications to DataTable."
What is a lock statement and how can I use it ?
What causes the errors "There is no row at position 601." and "DataTable
internal index is corrupted: '5'. " ,
and how to fix it ? Thank you
The timer code in the main program:
Private Sub TimerStat_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TimerStat.Tick
dim m_da As OleDb.OleDbDataAdapter
dim m_cmd As OleDb.OleDbCommand
Dim m_ds As DataSet
m_cmd = New OleDb.OleDbCommand
With m_cmd
.Connection = adoConOLE
.CommandText = "select a,b from stat"
End With
m_da = New OleDb.OleDbDataAdapter
m_ds = New DataSet
m_da.Fill(m_ds)
m_clsStat = New clsStat
m_clsStat.CopyStatTable(m_ds)
If Not (BestSession) Is Nothing Then 'this is my thread
BestSession.oclsStat = m_clsStat
End If
rs.CloseRS()
rs = Nothing
end sub
This is the clsStat.vb code:
Dim m_dtStat As DataTable
Public Sub CopyStatTable(ByVal m_ds As dataset)
m_dtStat = m_ds.Tables(0).Copy()
end sub
Public Function SelectStat(ByVal Account As String, ByVal sCol As String) As
DataRow()
SelectStat = m_dtStat.Select(sCol & "='" & Trim(Account) & "'") '--> error
here
end sub