Hi all
just look that code I am using enum for returning a object, In the function I make five type of object but my question is how to do this with a single object.
Means if the enum type is datareader then it will create the object of datareader, if the enum type is datatable then it create the object of datatable, same for the dataset and so on.

look the code


C# Code:
  1. public enum GetDataType
  2. {
  3.     _DataReader,
  4.     _DataSet,
  5.     _DataTable,
  6.     _DataCommand,
  7.     _DataAdapter
  8. }
  9.  
  10. public object ExecuteDb(string QueryString, GetDataType ss)
  11. {
  12.     try {
  13.         DbDataAdapter dap;
  14.         dap = new OleDb.OleDbDataAdapter(QueryString, myConnection);
  15.         tcomm.CommandText = QueryString;
  16.         //*************** Returning Adapter
  17.         if (ss == GetDataType._DataAdapter) {
  18.             return dap;
  19.         }
  20.         //**************** Returning Data Reader
  21.         if (ss == GetDataType._DataReader) {
  22.             OleDb.OleDbDataReader tread;
  23.             tread = tcomm.ExecuteReader();
  24.             return tread;
  25.         }
  26.         //*****************Returning DataSet
  27.         if (ss == GetDataType._DataSet) {
  28.             DataSet ds = new DataSet();
  29.             dap.Fill(ds);
  30.             return ds;
  31.         }
  32.         //*****************Executing Command
  33.         tcomm.ExecuteNonQuery();
  34.         //*****************Returning DataTable
  35.         if (ss == GetDataType._DataTable) {
  36.             DataTable datatab = new DataTable();
  37.             dap.Fill(datatab);
  38.             return datatab;
  39.         }
  40.         //*****************Executing Command
  41.         if (ss == GetDataType._DataCommand) {
  42.             tcomm.ExecuteNonQuery();
  43.         }
  44.     }
  45.    
  46.     catch (Exception ex) {
  47.         throw ex;
  48.     }