Created
September 25, 2011 19:46
-
-
Save LordAmit/1241044 to your computer and use it in GitHub Desktop.
Class QueryExecutor is in charge of queries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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