public string ExecuteNonQuery(SqlConnection dbCon, string Query) { string str; clsUtil _clsUtil = new clsUtil(); if (dbCon.State != ConnectionState.Open) { str = "FAIL::Connection Not Opened"; } else { SqlCommand sqlCommand = new SqlCommand(Query, dbCon); try { sqlCommand.ExecuteNonQuery(); _clsUtil.writeLog(string.Concat("DB SUCCESS : ", Query)); str = "SUCCESS"; } catch (Exception exception1) { Exception exception = exception1; _clsUtil.writeLog(string.Concat("DBEXECN ERR : ", Query)); str = string.Concat("FAIL::", exception.ToString()); } } return(str); }
public DataSet ExecuteDSQuery(SqlConnection dbCon, string Query) { DataSet dataSet; DataSet dataSet1 = new DataSet(); clsUtil _clsUtil = new clsUtil(); if (dbCon.State != ConnectionState.Open) { _clsUtil.writeLog("Connection FAIL"); dataSet = new DataSet(); } else { try { SqlDataAdapter sqlDataAdapter = new SqlDataAdapter() { SelectCommand = new SqlCommand(Query, dbCon) }; sqlDataAdapter.Fill(dataSet1); _clsUtil.writeLog(string.Concat("DB SUCCESS : ", Query)); dataSet = dataSet1; } catch (Exception exception1) { Exception exception = exception1; _clsUtil.writeLog(string.Concat("DBEXEC ERR : ", Query)); _clsUtil.writeLog(string.Concat("DBEXEC ERR : ", exception.ToString())); dataSet = new DataSet(); } } return(dataSet); }
public string ExecuteNonQuery(SqlConnection dbCon, SqlTransaction tran, string Query) { string str; clsUtil _clsUtil = new clsUtil(); if (dbCon.State != ConnectionState.Open) { str = "FAIL::Connection Not Opened"; } else { (new SqlCommand(Query, dbCon, tran)).ExecuteNonQuery(); _clsUtil.writeLog(string.Concat("DB SUCCESS : ", Query)); str = "SUCCESS"; } return(str); }
public DataSet ExecuteDSQuery(SqlConnection dbCon, SqlTransaction tran, string Query) { DataSet dataSet; DataSet dataSet1 = new DataSet(); clsUtil _clsUtil = new clsUtil(); if (dbCon.State != ConnectionState.Open) { _clsUtil.writeLog("Connection FAIL"); dataSet = new DataSet(); } else { SqlDataAdapter sqlDataAdapter = new SqlDataAdapter() { SelectCommand = new SqlCommand(Query, dbCon, tran) }; sqlDataAdapter.Fill(dataSet1); _clsUtil.writeLog(string.Concat("DB SUCCESS : ", Query)); dataSet = dataSet1; } return(dataSet); }
public string BuildQuery() { int i; string str; string str1 = ""; StringBuilder stringBuilder = new StringBuilder(); clsUtil _clsUtil = new clsUtil(); str1 = this.ValidateMe(); if (!_clsUtil.Left(str1, 4).Equals("FAIL")) { if (this.qtProc == QueryType.SELECT) { stringBuilder.Append("SELECT "); if ((this.Page == 0 ? false : this.PageCnt != 0)) { int page = this.Page * this.PageCnt; stringBuilder.Append(string.Concat(" TOP ", page.ToString())); } int num = 0; for (i = 0; i < this.arrCols.Count; i++) { if (this.arrCols[i].ToString().Length > 0) { if (num > 0) { stringBuilder.Append(", "); } stringBuilder.Append(this.arrCols[i].ToString()); num++; } } stringBuilder.Append(" FROM "); stringBuilder.Append(this.Table); stringBuilder.Append(" WHERE 1 = 1 "); for (i = 0; i < this.arrWCols.Count; i++) { stringBuilder.Append(" AND "); stringBuilder.Append(this.arrWCols[i].ToString()); stringBuilder.Append(string.Concat(" = '", this.arrWVals[i].ToString(), "'")); } if (this.arrGCols.Count > 0) { for (i = 0; i < this.arrGCols.Count; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append(this.arrGCols[i].ToString()); } } stringBuilder.Append(this.Order); } if (this.qtProc == QueryType.INSERT) { stringBuilder.Append("INSERT INTO "); stringBuilder.Append(this.Table); stringBuilder.Append("("); for (i = 0; i < this.arrCols.Count; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append(this.arrCols[i].ToString()); } stringBuilder.Append(")"); stringBuilder.Append(" VALUES "); stringBuilder.Append("("); for (i = 0; i < this.arrVals.Count; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append(this.arrVals[i].ToString()); } stringBuilder.Append(")"); } if (this.qtProc == QueryType.UPDATE) { stringBuilder.Append("UPDATE "); stringBuilder.Append(this.Table); stringBuilder.Append(" SET "); for (i = 0; i < this.arrCols.Count; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append(this.arrCols[i].ToString()); stringBuilder.Append(" = "); stringBuilder.Append(this.arrVals[i].ToString()); } stringBuilder.Append(" WHERE 1 = 1 "); for (i = 0; i < this.arrWCols.Count; i++) { stringBuilder.Append(" AND "); stringBuilder.Append(this.arrWCols[i].ToString()); stringBuilder.Append(string.Concat(" = '", this.arrWVals[i].ToString(), "'")); } } if (this.qtProc == QueryType.DELETE) { stringBuilder.Append("DELETE FROM "); stringBuilder.Append(this.Table); stringBuilder.Append(" WHERE 1 = 1 "); for (i = 0; i < this.arrWCols.Count; i++) { stringBuilder.Append(" AND "); stringBuilder.Append(this.arrWCols[i].ToString()); stringBuilder.Append(string.Concat(" = '", this.arrWVals[i].ToString(), "'")); } } str = stringBuilder.ToString(); } else { str = str1; } return(str); }