Database access speed

Z

Zahid

Hi,

I have a SQLServerCE database linked to my PocketPC
application. What i am doing is reading a row of data
from a table and assigning the values from that row to a
custom control (picture button). The rows in the database
table contain the configuration setting of the custom
designed picture button such as background color,
foreground colour, text etc.

I have about 16 of these custom controls on my form and
the user will regularly need to refresh these so as to
read new picture button settings from the database. The
problem im having is that the refresh speed is a little
slow (4 secs)- causing a delay for the user. I would like
to reduce it to at most 2 secs.

Is there a faster alternative that is not memory
intensive? There will be times probably where I will need
to read 70/80 rows from the database.

Here is my code:

Dim Counter As Integer = 0
Dim bColorFromDB, fColorFromDB As String
gMyCommand.CommandText = "Select ItemText,
ForeGround,Background, ListNo from ListItems"

gRdr = gMyCommand.ExecuteReader
Dim NewStr As String

While (Counter < 16 And gRdr.Read())
bDo_PaintBackGround = False
m = Frm2.Panel1.Controls(Counter)

'Read the Button color setting from the
'database field backgroundColor

m.Text = gRdr.GetString(0)
fColorFromDB = gRdr.GetInt32(1)
bColorFromDB = gRdr.GetInt32(2)

If fColorFromDB = 1 Then
m.ForeColor = Color.FromArgb(0, 0, 0)
ElseIf fColorFromDB = 2 Then
m.ForeColor = Color.FromArgb(0, 0, 168)
ElseIf fColorFromDB = 3 Then
m.ForeColor = Color.FromArgb(0, 168, 0)
Else

End If


If bColorFromDB = 1 Then
m.buttonImg = m.MakeBitmap(0, 0, 0,
m.Width, m.Height)
m.RgbR = 0
m.RgbG = 0
m.RgbB = 0
ElseIf bColorFromDB = 2 Then
m.buttonImg = m.MakeBitmap(0, 0, 168,
m.Width, m.Height)
m.RgbR = 0
m.RgbG = 0
m.RgbB = 168
ElseIf bColorFromDB = 3 Then
m.buttonImg = m.MakeBitmap(0, 168, 0,
m.Width, m.Height)
m.RgbR = 0
m.RgbG = 168
m.RgbB = 0
Else

End If

bDo_PaintBackGround = True
Frm2.Panel1.Controls(Counter).Refresh()
Counter += 1
End While



Thanks in advance.
 
A

Alex Yakhnin, eMVP

So which part is actually slow for you?
Reading from the database, assigning a new properties or call to this
MakeBitmap method of yours...
 
Z

Zahid

Hi,

Im not too sure... What is very clear is that when the
buttons are refreshed with the data from the database the
user sees one button at a time being refreshed - there is
about 1 second gap between each buttons refresh.

It may be something in my MakeBitmap method. Here is the
code for my MakeBitmap method:

Function MakeBitmap(ByVal R As Integer, ByVal G As
Integer, ByVal B As Integer, ByVal width As Integer,
ByVal height As Integer) As Bitmap

Dim bmp As New Bitmap(width, height)
g1 = Graphics.FromImage(bmp)

g1.FillRectangle(New SolidBrush(Color.FromArgb(R,
G, B)), 0, 0, bmp.Width, bmp.Height)

Return bmp
End Function

Ive even tried g1.Clear(New Color) but this is just as
slow.

In my Picture Button Class (Custom designed button) ive
got the following code:

Protected Overrides Sub OnPaintBackground(ByVal pEvent
As System.Windows.Forms.PaintEventArgs)

If bDo_PaintBackGround = True Then
MyBase.OnPaintBackground(pEvent)
End If

End Sub


Any ideas?
Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top