Skip to content

Instantly share code, notes, and snippets.

@LordAmit
Created September 25, 2011 19:46
Show Gist options
  • Save LordAmit/1241044 to your computer and use it in GitHub Desktop.
Save LordAmit/1241044 to your computer and use it in GitHub Desktop.
Class QueryExecutor is in charge of queries.
class QueryExecutor {
string strQuery;
CreateConnection c;
public QueryExecutor(string query) {
strQuery = query;
c = new CreateConnection();
}
public QueryExecutor(string query, string strConnection) {
strQuery = query;
c = new CreateConnection(strConnection);
}
public void ExecuteQuery() {
if (c.EstablishConnection()) {
SqlCommand cmd = new SqlCommand(strQuery, c.sqlConnection);
try {
cmd.ExecuteNonQuery();
MessageBox.Show("Successfully Command Executed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
c.CloseConnection();
}
catch (Exception e) {
MessageBox.Show("Query Executor Error: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
c.CloseConnection();
}
}
else {
MessageBox.Show("Error Establishing Connection.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
c.CloseConnection();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment