I have 2 classes. With the Generic Data Access class I can get the departments from the stored procedure GetDepartments. My problem is that in the Catalog Access class and especially in the public static DataTable ExecuteSelectCommand(DbCommand command)(execute a command and returns the results as a DataTable object) I dont know what I must write in the CATCH loop or how to leave it blank.Can anyone please help me to complete this part?Or maybe how can i change it without Try-catch.
using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
public static class GenericDataAccess
{
static GenericDataAccess()
{
}
public static DataTable ExecuteSelectCommand(DbCommand command)
{
DataTable table;
try
{
command.Connection.Open();
DbDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
reader.Close();
}
catch (...)
{
......
}
finally
{
command.Connection.Close();
}
return table;
}
public static DbCommand CreateCommand()
{
string dataProviderName = BalloonShopConfiguration.DbProviderName;
string connectionString = BalloonShopConfiguration.DbConnectionString;
DbProviderFactory factory = DbProviderFactories.GetFactory(dataProviderName);
DbConnection conn = factory.CreateConnection();
conn.ConnectionString = connectionString;
DbCommand comm = conn.CreateCommand();
comm.CommandType = CommandType.StoredProcedure;
return comm;
}
}
**The Catalog Access class:**
using System;
using System.Data;
using System.Data.Common;
public static class CatalogAccess
{
static CatalogAccess()
{
}
public static DataTable GetDepartments()
{
DbCommand comm = GenericDataAccess.CreateCommand();
comm.CommandText = "GetDepartments";
return GenericDataAccess.ExecuteSelectCommand(comm);
}
}
If you don’t know what to do or don’t want to handle any exceptions, leave with
catchout. This is valid:..that way, any exceptions will be passed up to the method that called your method. If there is a problem (exception) in the
tryblock, the method will exit, but not before any code infinallyis executed.