Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult SomeAction(MyModel model) {
- if(someCondition = true) {
- QueryDatabase();
- }
- }
- private void QueryDatabase() {
- SqlConnection connection = null;
- SqlDataReader dataReader = null;
- List<NotificationDetails> lDeviceCredentials = new List<NotificationDetails>();
- try {
- string connectionString = ConfigurationManager.ConnectionStrings["myEntity"].ConnectionString;
- EntityConnectionStringBuilder stringBuilder = new EntityConnectionStringBuilder(connectionString);
- string providerConnString = stringBuilder.ProviderConnectionString + ";password=myPassword";
- string someString= null;
- string otherString = null;
- using (connection = new SqlConnection(providerConnString)) {
- connection.Open();
- using (SqlCommand command = new SqlCommand("SELECT myfirstcolumn, mysecondcolumn FROM tblsample WHERE member = 1", connection)) {
- using (dataReader = command.ExecuteReader()) {
- if (dataReader != null) {
- while (dataReader.Read()) {
- someString= dataReader.GetString(dataReader.GetOrdinal("myfirstcolumn"));
- otherString = dataReader.GetString(dataReader.GetOrdinal("mysecondcolumn"));
- }
- if ((!string.IsNullOrEmpty(someString)) && (!string.IsNullOrEmpty(otherString ))) {
- // Do Something
- } else if (!string.IsNullOrEmpty(someString)) {
- // Do Something
- } else if (!string.IsNullOrEmpty(otherString )) {
- // Do Something
- } else {
- // Don't do anything.
- }
- }
- }
- }
- }
- } catch (Exception ex) {
- Debug.WriteLine(ex.ToString());
- }
- }
Add Comment
Please, Sign In to add comment