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:
public enum GetDataType { _DataReader, _DataSet, _DataTable, _DataCommand, _DataAdapter } public object ExecuteDb(string QueryString, GetDataType ss) { try { DbDataAdapter dap; dap = new OleDb.OleDbDataAdapter(QueryString, myConnection); tcomm.CommandText = QueryString; //*************** Returning Adapter if (ss == GetDataType._DataAdapter) { return dap; } //**************** Returning Data Reader if (ss == GetDataType._DataReader) { OleDb.OleDbDataReader tread; tread = tcomm.ExecuteReader(); return tread; } //*****************Returning DataSet if (ss == GetDataType._DataSet) { DataSet ds = new DataSet(); dap.Fill(ds); return ds; } //*****************Executing Command tcomm.ExecuteNonQuery(); //*****************Returning DataTable if (ss == GetDataType._DataTable) { DataTable datatab = new DataTable(); dap.Fill(datatab); return datatab; } //*****************Executing Command if (ss == GetDataType._DataCommand) { tcomm.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; }




Reply With Quote