Click here to Skip to main content
14,982,408 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Thanks in Advance,

Please give sample code for displaying the progress bar while inserting the multiple record to database,
Am insering multiple records by using for loop, on each loop an statement is inserted to database, untile the loop ends i have to display the progress bar how can i achive this, Please help,

Thanks in Adavance,

In order to by a progress bar, you have to create it, either on the current form where you make it visible, or as a separate modal form (meaning cannot interact with parent form while modal form is open). If you want the progress bar to show progress, you really can't with a database call unless you break the inster/delete/etc into separate parts. Basically you have to do the progress bar yourself. Knowing true progress can be diffucult, and this is why many times you will see progress bars that do not appear linear; it is difficult to know what the progress really is. Wish that there was a feedback on SQL calls that would give progress.

ANother thing is that you will want to do the SQL call on a background thread, probably using a BackgroundWorker. Suggest you search the site for sameple code for background workers. Here is one article: BackgroundWorker Threads and Supporting Cancel[^]

Hope this helps.
ProEnggSoft 23-Mar-12 2:35am
Good explanation and link to article. 5!
MemberCva 23-Mar-12 3:10am
Thanks Clifford Nelson ,

How can i implement this in
MemberCva 23-Mar-12 3:17am
Thanks MaulikDusara,

This is my code i have used here total is the no of scripts to be inserted.

RadProgressContext progress = RadProgressContext.Current;
progress.Speed = "N/A";

for (int i = 0; i < total; i++)
progress.PrimaryTotal = 1;
progress.PrimaryValue = total;
progress.PrimaryPercent = 100;

progress.SecondaryTotal = total;
progress.SecondaryValue = i;
progress.SecondaryPercent = i;

progress.CurrentOperationText = Filename + " Step " + i.ToString();

if (!Response.IsClientConnected)
//Cancel button was clicked or the browser was closed, so stop processing

progress.TimeEstimated = (total - i) * 100;
//Stall the current thread for 0.1 seconds

The scripts are inserted to db in another loop as u mentioned as datarows .
what else i have to do pls correct my codeing,

thanks in advance.

Your Solution :
This is very simple follow below steps.
1) Set Maximum value for Progress bar control with row count either from datatable or gridview etc..<br />
2) Set initial value to zero or minimum value of progress bar control.<br />
3) In your loop you need to increase your progress bar control's value with 1.

Sample Code:

progressBar1.Maximum = dtTable.Rows.Count;
progressBar1.Value = progressBar1.Minimum;

foreach (DataRow vRow in dtTable.Rows)
    //TODO : Your INSERT, UPDATE, DELETE Or any Operation/Execution
Clifford Nelson 23-Mar-12 3:30am
I am sorry, did not pay attention to the fact that this was ASP.NET. Here is an article on the AJAX progress bar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900