SQL Load Progress bar

A

Adriano

Hello,

can anyone help me to make progress bar in the status bar that will show the
status of SQL data loading into dataset,

tnx in advance,

Adriano
 
C

Cor Ligthert

Hi Adriano,

As far as I know can this can only be done when you are using the datareader
by your own code to fill the dataset.Using the dataadapter it is a one time
method which has no events for the fill. (What you ask is possible while
updating).

Probably a lot of work for a progress bar, just using an avi or an animated
gif gives in my idea almost the same result.

I hope this helps?

Cor
 
A

Adriano

hello Cor,

i used to see this in one program, that's why i'm asking,
the SQL server is located in remote computer and sometimes it takes long to
load,
do you have any ideas how to do that?

tnx in advance,
Adriano
 
C

Cor Ligthert

Hi Adriano,

Keep in mind that it will not make your process faster, have a look why the
loading of the data is so slow.

You can look in this thread
http://groups.google.com/groups?hl=...roup=microsoft.public.dotnet.framework.adonet

And you see answers however than it is mostly for the update and than people
see that after a while.

Bernie Yaeger is very much been busy with it, so maybe you can find
something using his name in a search.

The best place to ask questions how to make your process faster is in the
newsgroup

Adonet
<
Web interface:

<http://communities2.microsoft.com/communities/newsgroups/en-us/?dg=microsof
t.public.dotnet.framework.adonet>


I hope this helps?

Cor
 
A

Adriano

I know that it's not gonna make database load faster,
i just want to learn how to do that,

regards,
Adriano
 
B

Bernie Yaeger

Hi Adriano,

It's not too difficult.

Start by adding a timer and a progress bar to the form, and add a public
variable to the form class as
Public alarmcounter As Integer = 1

Then set the timer in the load event:
timer1.start

Add a timer_tick method with this code:
alarmcounter += 1

If alarmcounter > 2 Then

Timer1.Stop()

loader.PerformClick()

End If

'loader' is a button control that simply says 'Loading....' and is set not
to be able to be clicked. However, it does have a click event, thus the
performclick above. Then this in the click event:

loader.Enabled = False



me.parent.cursor = Cursors.WaitCursor

Application.DoEvents()

If gl_sqlexpression = "6 <> 7" Then

Me.SqlSelectCommand1.CommandText = "SELECT rinvnum, invnum, qty, title,
brname, bipad, issuecode, imcacct, uprice, cprice, shi" & _

"p_dt, billed, onsaledt, bipterms, ptype, rectype, isquart, raf, ponumber,
vflag, mcycle," & _

" rowid FROM invdet"

Else

Me.SqlSelectCommand1.CommandText = "SELECT rinvnum, invnum, qty, title,
brname, bipad, issuecode, imcacct, uprice, cprice, shi" & _

"p_dt, billed, onsaledt, bipterms, ptype, rectype, isquart, raf, ponumber,
vflag, mcycle," & _

" rowid FROM invdet WHERE " & gl_sqlexpression

'" rowid FROM invdet WHERE bipad in ('18770', '18778', '01503')"

End If

SqlDataAdapter1.SelectCommand.CommandTimeout = 1200

Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1

If Mid(gl_sqlexpressioncount, 1, 1) <> "z" Then

gl_sqlexpressioncount = gl_sqlexpression

End If

Dim oconn As New SqlConnection(globalconnectionstring)

oconn.ConnectionString = globalconnectionstring

oconn.Open()

Dim cmd As SqlCommand = oconn.CreateCommand()

cmd.CommandText = "select count(*) from invdet WHERE (ship_dt >= " & Chr(39)
& gl_browsestartdate & Chr(39) & ")"

cmd.CommandText = "select count(*) from invdet where " &
gl_sqlexpressioncount

cmd.CommandTimeout = 1200

Dim rows As Integer

If Mid(gl_sqlexpressioncount, 1, 1) = "z" Then

rows = CInt(Mid(gl_sqlexpressioncount, 2))

Else

Try

rows = CInt(cmd.ExecuteScalar)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End If

oconn.Close()

Dim dt As DataTable

dt = Invdetds2.Tables(0)

AddHandler dt.RowChanged, New DataRowChangeEventHandler(AddressOf
DataTableRow_Changed)

pbar.Maximum = rows

pbar.Step = pbar.Maximum / 30

pbar.Visible = True

pbar.Minimum = 1

' Set the initial value of the ProgressBar.

pbar.Value = 1

pbar.PerformStep()

Try

Me.SqlDataAdapter1.Fill(Me.Invdetds2)

Catch ex As Exception

MessageBox.Show("Invalid SQL Expression", "SQL Error", MessageBoxButtons.OK,
MessageBoxIcon.Hand)

Me.Close()

Exit Sub

End Try

The key is an event called datatablerow_changed, which is added via
addhandler in the code above; here's the code for the datatablerow_changed
event:

Public Sub DataTableRow_Changed(ByVal Sender As Object, ByVal e As
System.Data.DataRowChangeEventArgs)

' The DataRow has changed. update pbar

glf_icount += 1

If glf_icount > (pbar.Maximum / 15) Then

glf_icount = 0

pbar.PerformStep()

Application.DoEvents()

End If

Once the table loads, simply make the button and the progress bar invisible.

HTH,

Bernie Yaeger
 

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