J
Jon Brunson
Morning all,
I just want some advice really. I've got the following VB.NET code, and
it seems rather slow, and I was wondering if anyone could see a/some
way/s of speeding it up a little/lot.
Thanks in advance
[VB.NET]
' Me.barCurrent is a ProgressBar
Dim sqlLocal As New SqlCeConnection("Data Source='\Program
Files\TestApp\Data.sdf'")
sqlLocal.Open()
Dim sLastUpdateTimes As New Text.StringBuilder
Dim cmdLocalTableCount As New SqlCeCommand("SELECT COUNT(*) FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", sqlLocal)
Dim cmdLocalTables As New SqlCeCommand("SELECT TABLE_NAME FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", sqlLocal)
Dim cmdLastUpdateExists As New SqlCeCommand("SELECT COUNT(*) FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME =
'LastUpdate'", sqlLocal)
Dim cmdLastUpdatedTime As New SqlCeCommand("", sqlLocal)
cmdLastUpdateExists.Parameters.Add("@TableName", SqlDbType.NVarChar)
Me.barCurrent.Value = 0
Dim iTable As Integer = 0, iTableCount As Integer =
CInt(cmdLocalTableCount.ExecuteScalar())
Dim drLocalTables As SqlCeDataReader = cmdLocalTables.ExecuteReader()
While drLocalTables.Read()
Dim sTableName As String = drLocalTables.GetString(0)
cmdLastUpdateExists.Parameters(0).Value = sTableName
If CInt(cmdLastUpdateExists.ExecuteScalar()) = 1 Then
cmdLastUpdatedTime.CommandText = "SELECT MAX(LastUpdate) FROM """ +
sTableName + """"
Dim LastUpdate As Object = cmdLastUpdatedTime.ExecuteScalar()
If Not (LastUpdate Is DBNull.Value) Then
If sLastUpdateTimes.Length > 0 Then _
sLastUpdateTimes.Append(",")
sLastUpdateTimes.Append(sTableName + "=")
sLastUpdateTimes.Append(CDate(LastUpdate).ToString("yyyy-MM-dd
HH\:mm\:ss.fff"))
End If
End If
iTable += 1
Me.barCurrent.Value = (iTable / iTableCount) * 100
End While
drLocalTables.Close()
sqlLocal.Close()
[/VB.NET]
I just want some advice really. I've got the following VB.NET code, and
it seems rather slow, and I was wondering if anyone could see a/some
way/s of speeding it up a little/lot.
Thanks in advance
[VB.NET]
' Me.barCurrent is a ProgressBar
Dim sqlLocal As New SqlCeConnection("Data Source='\Program
Files\TestApp\Data.sdf'")
sqlLocal.Open()
Dim sLastUpdateTimes As New Text.StringBuilder
Dim cmdLocalTableCount As New SqlCeCommand("SELECT COUNT(*) FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", sqlLocal)
Dim cmdLocalTables As New SqlCeCommand("SELECT TABLE_NAME FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", sqlLocal)
Dim cmdLastUpdateExists As New SqlCeCommand("SELECT COUNT(*) FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME =
'LastUpdate'", sqlLocal)
Dim cmdLastUpdatedTime As New SqlCeCommand("", sqlLocal)
cmdLastUpdateExists.Parameters.Add("@TableName", SqlDbType.NVarChar)
Me.barCurrent.Value = 0
Dim iTable As Integer = 0, iTableCount As Integer =
CInt(cmdLocalTableCount.ExecuteScalar())
Dim drLocalTables As SqlCeDataReader = cmdLocalTables.ExecuteReader()
While drLocalTables.Read()
Dim sTableName As String = drLocalTables.GetString(0)
cmdLastUpdateExists.Parameters(0).Value = sTableName
If CInt(cmdLastUpdateExists.ExecuteScalar()) = 1 Then
cmdLastUpdatedTime.CommandText = "SELECT MAX(LastUpdate) FROM """ +
sTableName + """"
Dim LastUpdate As Object = cmdLastUpdatedTime.ExecuteScalar()
If Not (LastUpdate Is DBNull.Value) Then
If sLastUpdateTimes.Length > 0 Then _
sLastUpdateTimes.Append(",")
sLastUpdateTimes.Append(sTableName + "=")
sLastUpdateTimes.Append(CDate(LastUpdate).ToString("yyyy-MM-dd
HH\:mm\:ss.fff"))
End If
End If
iTable += 1
Me.barCurrent.Value = (iTable / iTableCount) * 100
End While
drLocalTables.Close()
sqlLocal.Close()
[/VB.NET]