public bool ExecNonQuery(DbCommand args) { if (isOpened) { if ((args != null) && (args.CommandText != String.Empty)) { SqlCommand command = null; if (!transactionIsActive) { command = new SqlCommand(args.CommandText, connection); } else { command = new SqlCommand(args.CommandText, connection, transaction); } if (args.Parameters != null) { command.Parameters.AddRange(args.Parameters); } return (command.ExecuteNonQuery() > 0); } else { Logger.Instance.WriteToLog("Error in command arguments."); } } else { Logger.Instance.WriteToLog("Error: connection was not opened."); } return false; }
public DataSet ExecSelect(DbCommand args) { if (isOpened) { if ((args != null) && (args.CommandText != String.Empty)) { SqlCommand command = null; if (!transactionIsActive) { command = new SqlCommand(args.CommandText, connection); } else { command = new SqlCommand(args.CommandText, connection, transaction); } if (args.Parameters != null) { command.Parameters.AddRange(args.Parameters); } var dataAdapter = new SqlDataAdapter(command); var dataSet = new DataSet(connection.Database); dataAdapter.Fill(dataSet); return dataSet; } else { Logger.Instance.WriteToLog("Error in command arguments."); } } else { Logger.Instance.WriteToLog("Error: connection was not opened."); } return null; }
private List<PageModel> GetAllPages() { if (contentCache.Count == 0) { try { connection.OpenConnection(); DbCommand command = new DbCommand("select * from tb_Pages"); DataSet set = connection.ExecSelect(command); foreach (DataRow row in set.Tables[0].Rows) { contentCache.Add(CreateContentCacheInstance(row)); } } finally { connection.CloseConnection(); } } return contentCache; }