public ResultArgs Update(object command, Common.CommandType cmdType) { result = new ResultArgs(); try { objCommand = new SqlCommand(); objCommand.Connection = objConnection; if (hasTransaction) { objCommand.Transaction = objTransaction; } if (cmdType == Common.CommandType.StroeProcedure) { objCommand.CommandType = CommandType.StoredProcedure; QueryFetch objQueryFetch = new QueryFetch(); objCommand.CommandText = objQueryFetch.GetQuery(command); } else if (cmdType == Common.CommandType.Query) { objCommand.CommandType = CommandType.Text; QueryFetch objQueryFetch = new QueryFetch(); objCommand.CommandText = objQueryFetch.GetQuery(command); } BindParameterWithCommand(); if (objConnection.State != ConnectionState.Open) { objConnection.Open(); } result.AffectedRows = objCommand.ExecuteNonQuery(); result.Success = true; } catch (Exception ex) { Logger.WriteErrorLog(objCommand.CommandText); foreach (SqlParameter item in parameterCollection) { Logger.WriteErrorLog(string.Format("Name - {0} - Value - {1}", item.ParameterName, item.Value)); } Logger.WriteErrorLog(ex.Message); result.Message = ex.Message; result.AffectedRows = 0; result.Success = false; } finally { if (!hasTransaction) { objConnection.Close(); } parameterCollection.Clear(); } return(result); }
public ResultArgs Fetch(object command, Common.CommandType cmdType) { result = new ResultArgs(); try { objCommand = new SqlCommand(); objCommand.Connection = objConnection; if (hasTransaction) { objCommand.Transaction = objTransaction; } if (cmdType == Common.CommandType.StroeProcedure) { objCommand.CommandType = CommandType.StoredProcedure; QueryFetch objQueryFetch = new QueryFetch(); objCommand.CommandText = objQueryFetch.GetQuery(command); } else if (cmdType == Common.CommandType.Query) { objCommand.CommandType = CommandType.Text; QueryFetch objQueryFetch = new QueryFetch(); objCommand.CommandText = objQueryFetch.GetQuery(command); } BindParameterWithCommand(); objAdapter = new SqlDataAdapter(); if (objConnection.State != ConnectionState.Open) { objConnection.Open(); } objAdapter.SelectCommand = objCommand; DataTable dtresult = new DataTable(); objAdapter.Fill(dtresult); result.Source = dtresult; result.Success = true; if (result.Source != null && result.Source.Rows.Count > 0) { result.AffectedRows = result.Source.Rows.Count; } else { result.AffectedRows = 0; result.Message = "Proc returned no records."; } } catch (Exception ex) { result.Message = ex.Message; Logger.WriteErrorLog(objCommand.CommandText); foreach (SqlParameter item in parameterCollection) { result.Message += objCommand.CommandText; Logger.WriteErrorLog(string.Format("Name - {0} - Value - {1}", item.ParameterName, item.Value)); } Logger.WriteErrorLog(ex.Message); result.Success = false; result.AffectedRows = 0; } finally { if (!hasTransaction) { objConnection.Close(); } parameterCollection.Clear(); } return(result); }