2. public class DataManupulation (Data Layer)
1. RETRIEVEpublic DataSet RetrieveToDataSet2(string spName, SqlParameter[] ParamCollection = null) { try { DataSet dsResult = new DataSet();
String strConnString = ConfigurationManager.ConnectionStrings["ADConnection"].ConnectionString; SqlConnection con = new SqlConnection(strConnString); SqlCommand com = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter();
con.Open(); com.Connection = con; com.CommandType = CommandType.StoredProcedure; com.CommandText = spName;
if (ParamCollection != null) { com.Parameters.AddRange(ParamCollection); }
da.SelectCommand = com; da.Fill(dsResult);
con.Close();
return dsResult;
} catch (Exception ex) { throw (ex); } }
2. INSERT public string InsertUpdateData(string spName, SqlParameter[] Param) { String strConnString = ConfigurationManager.ConnectionStrings["ADConnection"].ConnectionString; SqlConnection con = new SqlConnection(strConnString); SqlCommand com = new SqlCommand(); SqlTransaction trn; con.Open(); trn = con.BeginTransaction();
try { com.Connection = con; com.CommandType = CommandType.StoredProcedure; com.Parameters.AddRange(Param); com.CommandText = spName; com.Transaction = trn; com.ExecuteNonQuery(); trn.Commit();
string aaaa = com.Parameters[0].Value.ToString() + " " + com.Parameters[1].Value.ToString(); return aaaa;
} catch (Exception ex) { trn.Rollback(); throw (ex); } finally { con.Close(); } }