Int32 num = Convert.ToInt32(new OleDbCommand(cmdCount).ExecuteScalar());
I get an error that says "connection property has not been initialized". If I comment out that section of code and continue on I get the same error here (line 32):
reader = new OleDbCommand(cmdText).ExecuteReader();
I'm sure that I'm missing something simple here, I just can't see it. If one of you could point it out I would really appreciate it.
private void cmdVerify_Click(object sender, EventArgs e)
{
if (!(File.Exists(this.txtMDBPath.Text)))
{
MessageBox.Show("No Database Selected.");
cmdOpenMDB.Focus();
return;
}
OleDbDataReader reader = null;
OleDbConnection connection = null;
bool bAllFound = true;
this.progressBar1.Visible = true;
this.progressBar1.Minimum = 1;
this.progressBar1.Value = 1;
this.progressBar1.Step = 1;
connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + openFileDialog1.FileName);
connection.Open();
string cmdText = "SELECT FilePath, FileName FROM FileTable";
string cmdCount = "SELECT COUNT(*) FROM FileTable";
Int32 num = Convert.ToInt32(new OleDbCommand(cmdCount).ExecuteScalar());
iFullCount = num;
connection.Close();
this.progressBar1.Maximum = num;
connection.Open();
reader = new OleDbCommand(cmdText).ExecuteReader();
Cursor.Current = Cursors.WaitCursor;
try
{
while(reader.Read())
{
string strRawPath = reader["FilePath"].ToString();
string strDriveLetter = strRawPath.Substring(1, 1);
int iLength = strRawPath.Length;
string strTrimmedPath = strRawPath.Substring(4, iLength - 4);
this.lblStatus.Text = strDriveLetter + @":\" + strTrimmedPath + @"\" + reader["FileName"].ToString();
if (File.Exists(this.lblStatus.Text))
{
Application.DoEvents();
this.progressBar1.PerformStep();
if (this.bStop)
{
connection.Close();
Application.Exit();
}
}
else
{
{
this.txtReport.AppendText("Not Found: " + reader["FilePath"].ToString() + @"\" + reader["FileName"].ToString() + Environment.NewLine);
Application.DoEvents();
//this.progressBar1.PerformStep();
if (bAllFound)
{
bAllFound = false;
}
if (this.bStop)
{
connection.Close();
Application.Exit();
}
}
}
}
}
catch(Exception exception)
{
MessageBox.Show(exception.Message);
}
finally
{
if(reader !=null)
{
reader.Close();
}
if(connection.State == ConnectionState.Open)
{
connection.Close();
}
if (bAllFound)
{
txtReport.Text = "All " + iFullCount.ToString() + "files located.";
cmdExit.Focus();
}
else
{
cmdSaveReport.Enabled = true;
cmdSaveReport.Focus();
}
}
cmdSaveReport.Enabled = true;
}

New Topic/Question
Reply



MultiQuote





|