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.