protected DataSet ExecuteDataSet(string sqlCommandString) { DataSet retDataSet = new DataSet(); try { if ((lstDbParameters != null) && (lstDbParameters.Count > 0)) { for (int i = 0; i < lstDbParameters.Count; i++) { string parameter = lstDbParameters[i].ParameterName.ToString(); string value = lstDbParameters[i].Value.ToString(); if (!string.IsNullOrEmpty(parameter)) { if (value.IndexOf('\'') > -1) { value = value.Replace("\'", "\'\'"); } sqlCommandString = sqlCommandString.Replace(parameter, "'" + value + "'"); } } } GetConnection(); MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(); MySqlCommand mySqlCommand = new MySqlCommand(sqlCommandString, mySqlConnection); mySqlDataAdapter.SelectCommand = mySqlCommand; mySqlDataAdapter.Fill(retDataSet); } catch (MySqlException ex) { MySqlEXP mySqlExp = new MySqlEXP(ex.Message + "\r\n Query : " + sqlCommandString, ex); throw mySqlExp; } catch (Exception ex) { throw ex; } finally { CloseConnection(); } CloseConnection(); return retDataSet; }
protected object ExecuteScalar(string sqlCommandString) { object iRetVal = -9; try { if ((lstDbParameters != null) && (lstDbParameters.Count > 0)) { for (int i = 0; i < lstDbParameters.Count; i++) { if (!string.IsNullOrEmpty(lstDbParameters[i].ParameterName.ToString())) { sqlCommandString = sqlCommandString.Replace(lstDbParameters[i].ParameterName.ToString(), "'" + lstDbParameters[i].Value.ToString() + "'"); } } } GetConnection(); MySqlCommand mySqlCommand = new MySqlCommand(sqlCommandString, mySqlConnection); if (lstDbParameters != null) { lstDbParameters.Clear(); } iRetVal = mySqlCommand.ExecuteScalar(); if (iRetVal == null) { iRetVal = -9; } } catch (MySqlException ex) { MySqlEXP mySqlExp = new MySqlEXP(ex.Message + "\r\n Query : " + sqlCommandString, ex); throw mySqlExp; } catch (Exception ex) { throw ex; } finally { CloseConnection(); } CloseConnection(); return iRetVal; }