How can I put a progress bar inside this code:
(I was trying to use PerformStep method for counting rows in data table, and put this code, but no luck: http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbar.performstep.aspx)
private void DocumentInserting ()
{
string MyFilePath = System.IO.Path.GetTempPath() + @"MyNotices\";
string MyFolderPath = MyFilePath + @"Notices.xml";
DataSet ds = new DataSet();
ds.ReadXml(MyFolderPath, XmlReadMode.ReadSchema);
progressBar1.Visible = true;
label1.Visible = true;
label1.Text = progressBar1.Value.ToString() + " % finished";
progressBar1.Minimum = 1;
//I have started, but do not know how to do a loop for counting the rows in data table!
foreach (DataRow dr in ds.Tables[0].Rows)
{
string insertion = "INSERT INTO NoticeTable VALUES(@IDNotice, @Number, @Name)";
SqlCommand cmd1 = new SqlCommand(ObvestiloVnos, povezava);
cmd1.Parameters.Add("@IDNotice", SqlDbType.Int);
cmd1.Parameters.Add("@Number ", SqlDbType.VarChar, 50);
cmd1.Parameters.Add("@Name", SqlDbType.VarChar, 50);
cmd1.Parameters["@IDNotice"].Value = dr[0];
cmd1.Parameters["@Number"].Value = dr[1];
cmd1.Parameters["@Name"].Value = dr[2];
try
{
sqlConn.Open();
cmd1.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
sqlConn.Close();
ds = null;
}