R
Ryan
I have a unique situation and wondering if there's a different way of
doing it. I have a strongly typed dataset for a disconnected
environment. This dataset runs on a service so I want to clear the
rows every now and then to keep memory usage to a minimum. But if
dataset can't contact for the database for some reason, I want to be
able to hold the records (because the service will still continue to
collect data) and upload them later. Is there a way to clear the rows
that are marked as unchanged.
Here's my code...
Private Function PopulateTable(ByRef dt As DataTable, ByVal sqlCmd
As SqlCommand, ByVal payload() As String)
Dim i As Integer
Dim row As DataRow = dt.NewRow()
Dim sqlDa As New SqlDataAdapter
Try
sqlDa.InsertCommand = sqlCmd
row(0) = m_machineName
For i = 1 To payload.Length - 1
If i > dt.Columns.Count - 1 Then Exit For
If i = 1 Then
row(i) = Convert.ToDateTime(payload(i - 1).Trim())
Else
row(i) = payload(i - 1).Trim()
End If
Next
Catch ex As Exception
Debug.WriteLine("PopulateTable: " + ex.Message)
Finally
dt.Rows.Add(row)
sqlDa.Update(dt) <--- Calls .AcceptChanges() method and
marks rows as UnChanged
If dt.Rows.Count > 1600 Then
dt.Rows.Clear() <--- Want to clear unchanged rows
End If
sqlDa.Dispose()
End Try
End Function
GetChanges returns a copy of the data table not a reference. If I have
to iterate through rows I will but I was hoping for a better method.
doing it. I have a strongly typed dataset for a disconnected
environment. This dataset runs on a service so I want to clear the
rows every now and then to keep memory usage to a minimum. But if
dataset can't contact for the database for some reason, I want to be
able to hold the records (because the service will still continue to
collect data) and upload them later. Is there a way to clear the rows
that are marked as unchanged.
Here's my code...
Private Function PopulateTable(ByRef dt As DataTable, ByVal sqlCmd
As SqlCommand, ByVal payload() As String)
Dim i As Integer
Dim row As DataRow = dt.NewRow()
Dim sqlDa As New SqlDataAdapter
Try
sqlDa.InsertCommand = sqlCmd
row(0) = m_machineName
For i = 1 To payload.Length - 1
If i > dt.Columns.Count - 1 Then Exit For
If i = 1 Then
row(i) = Convert.ToDateTime(payload(i - 1).Trim())
Else
row(i) = payload(i - 1).Trim()
End If
Next
Catch ex As Exception
Debug.WriteLine("PopulateTable: " + ex.Message)
Finally
dt.Rows.Add(row)
sqlDa.Update(dt) <--- Calls .AcceptChanges() method and
marks rows as UnChanged
If dt.Rows.Count > 1600 Then
dt.Rows.Clear() <--- Want to clear unchanged rows
End If
sqlDa.Dispose()
End Try
End Function
GetChanges returns a copy of the data table not a reference. If I have
to iterate through rows I will but I was hoping for a better method.