Hi all, this my first post.
I'm newbie in C# and ASP.NET so be patient with me, I have a problem when declare object in the
try clause working in VS2010 Express:
ex.
protected void Names()
{
string strQuery;
OleDbDataReader myReader;
strQuery = "SELECT TOP 1 Name FROM Names";
try
{
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=e:\\project\\Db.mdb");
myConn.Open();
OleDbCommand myComm = new OleDbCommand(strQuery, myConn);
myReader = myComm.ExecuteReader();
}
catch (Exception er)
{
Response.Write("Error:" + er.Message);
}
finally
{
//found something
if (myReader.HasRows)
{
myReader.Read();
Session.Add("Name", myReader[0].ToString());
myReader.Close();
//reuse the myConn connection
strQuery = "SELECT bla bla bla WHERE bla bla bla";
OleDbCommand myComm2 = new OleDbCommand(strQuery, myConn);
myReader = myComm2.ExecuteReader();
myConn.Close();
}
}
}
The myComm declared in the Try clause appear undeclared at rest of routine and underlined like error, I can't declare it outside Try clause because it's the action to catch error.
What's I did not understand ?
Thanks in advance.