View Single Post
  #1 (permalink)  
Old August 27th, 2009, 02:54 AM
codehelp codehelp is offline
Authorized User
Points: 135, Level: 2
Points: 135, Level: 2 Points: 135, Level: 2 Points: 135, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2007
Location: , , .
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Default Exception handling

Hi,
I have a method which returns a data table.
The data access code is in a try catch block.

Code:
public DataTable GetData(string fileName)
        {
            string methodmessage;

            DataTable dt;

            string sqlSelect = "SELECT * FROM " + fileName;

            try
            {
                OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""");
                OleDbCommand cmd = new OleDbCommand(sqlSelect, cn);
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);

                dt = new DataTable("SalesRep");
                dt.Locale = CultureInfo.InvariantCulture;
                da.Fill(dt);
            }
            catch (OleDbException oleEx)
            {
                methodmessage = oleEx.Message;
            }

            return dt;
        }
In the calling part of the program I have it like this:

Code:
this.dtperson = new DataTable();
this.dtperson = Form1.GetData(@"C:\TempCsvFiles\person.CSV");
My question is if an exeception occurs in the GetData code, what needs to be done to handle that in the call

Code:
this.dtperson = Form1.GetData(@"C:\TempCsvFiles\person.CSV");
as the GetData method returns a data table.

Thanks and Regards.