tags:

views:

123

answers:

2

I have this insert query:

try {
  Cmd.CommandText = @"INSERT INTO BarcodTbl SELECT * FROM [Text;DATABASE=" + PathI + @"\].[Tmp.txt];";
  Cmd.ExecuteNonQuery();
  Cmd.Dispose();
} catch (Exception ex) { 
  MessageBox.Show(ex.Message); 
}

I have two questions:

  1. How can I run a progress-bar from the beginning to the end of the insert?

  2. If there is an error, I got the error exception and the action will stop - the query stops and the BarcodTbl is empty. How I can see the error and allow the query to continue filling the table?

+1  A: 

The way you're filling the table - directly from a text file - prevents any progress information. At no point do you know how many records have been inserted and how many left. To get some real sense of "progress", you may need to break the query into a loop of record chunks. You will then be able to advance the progress bar after each chunk. It'll also allow you upon failing to start over from that particular chunk.

If you want to keep this query as-is and still show a progress bar, you'll have to fake it. Add a thread with a time and advance the progress bar until the query ends. Or show another progress indicator (i.e. a rolling ball0 that does not commit you to accurate updates.

Traveling Tech Guy
+1  A: 

I agree with Traveling Tech Guy.
You can't show a progress when using this INSERT. Read parts from file and insert them in in a loop or just draw some progress that's not percent related - something that will be moving from left to right and back.
I would choose the second solution.

StupidDeveloper