public void SQLExecuteScalar(string sqlstr, ref uint index) { bool criticalarea = ClientManager.enteredcriarea; if (criticalarea) { ClientManager.LeaveCriticalArea(); } DatabaseWaitress.EnterCriticalArea(); try { if (sqlstr.Substring(sqlstr.Length - 1) != ";") { sqlstr += ";"; } sqlstr += "SELECT LAST_INSERT_ID();"; index = Convert.ToUInt32(MySqlHelper.ExecuteScalar(db, sqlstr)); } catch (Exception ex) { Logger.ShowSQL("Error on query:" + sqlstr, null); Logger.ShowSQL(ex, null); } DatabaseWaitress.LeaveCriticalArea(); if (criticalarea) { ClientManager.EnterCriticalArea(); } }
/// <summary> /// 执行一个SQL语句(INSERT)返回当前ID /// </summary> /// <param name="sql">SQL语句</param> /// <param name="a">临时变量</param> /// <returns>当前ID</returns> public int ExeSql(string sql, int a) { int identity = -1; bool criticalarea = ClientManager.enteredcriarea; if (criticalarea) { ClientManager.LeaveCriticalArea(); } DatabaseWaitress.EnterCriticalArea(); // 打开 this.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = this._conn; if (isTransaction == true) { cmd.Transaction = this._trans; } cmd.CommandText = sql + " select @@identity as 'identity'"; try { // 第一行第一列的值为当前ID SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { identity = int.Parse(dr[0].ToString()); } dr.Close(); } catch (Exception ex) { Logger.ShowSQL("Error on query:" + sql, null); Logger.ShowSQL(ex, null); } DatabaseWaitress.LeaveCriticalArea(); if (criticalarea) { ClientManager.EnterCriticalArea(); } // 释放 //this.Close(); return(identity); }
/// <summary> /// 获取DataTable /// </summary> /// <param name="sql">SQL语句</param> /// <returns>DataTable</returns> public DataTable GetDataTable(string sql) { bool criticalarea = ClientManager.enteredcriarea; if (criticalarea) { ClientManager.LeaveCriticalArea(); } DatabaseWaitress.EnterCriticalArea(); // 打开 this.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = this._conn; if (isTransaction == true) { cmd.Transaction = this._trans; } DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); cmd.CommandText = sql; da.SelectCommand = cmd; try { da.Fill(dt); } catch (Exception ex) { Logger.ShowSQL("Error on query:" + sql, null); Logger.ShowSQL(ex, null); } // 释放 //this.Close(); DatabaseWaitress.LeaveCriticalArea(); if (criticalarea) { ClientManager.EnterCriticalArea(); } return(dt); }
public DataRowCollection SQLExecuteQuery(string sqlstr) { DataRowCollection result; DataSet tmp; bool criticalarea = ClientManager.enteredcriarea; if (criticalarea) { ClientManager.LeaveCriticalArea(); } DatabaseWaitress.EnterCriticalArea(); try { tmp = MySqlHelper.ExecuteDataset(db, sqlstr); if (tmp.Tables.Count == 0) { throw new Exception("Unexpected Empty Query Result!"); } result = tmp.Tables[0].Rows; DatabaseWaitress.LeaveCriticalArea(); if (criticalarea) { ClientManager.EnterCriticalArea(); } return(result); } catch (Exception ex) { Logger.ShowSQL("Error on query:" + sqlstr, null); Logger.ShowSQL(ex, null); DatabaseWaitress.LeaveCriticalArea(); if (criticalarea) { ClientManager.EnterCriticalArea(); } return(null); } }
/// <summary> /// 执行一个SQL语句(UPDATE,INSERT) /// </summary> /// <param name="sql">SQL语句</param> public void ExeSql(string sql) { // 打开 bool criticalarea = ClientManager.enteredcriarea; if (criticalarea) { ClientManager.LeaveCriticalArea(); } DatabaseWaitress.EnterCriticalArea(); this.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = this._conn; if (isTransaction == true) { cmd.Transaction = this._trans; } cmd.CommandText = sql; try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Logger.ShowSQL("Error on query:" + sql, null); Logger.ShowSQL(ex, null); } DatabaseWaitress.LeaveCriticalArea(); if (criticalarea) { ClientManager.EnterCriticalArea(); } // 释放 //this.Close(); }
public void SQLExecuteNonQuery(string sqlstr) { bool criticalarea = ClientManager.enteredcriarea; if (criticalarea) { ClientManager.LeaveCriticalArea(); } DatabaseWaitress.EnterCriticalArea(); try { MySqlHelper.ExecuteNonQuery(db, sqlstr, null); } catch (Exception ex) { Logger.ShowSQL("Error on query:" + sqlstr, null); Logger.ShowSQL(ex, null); } DatabaseWaitress.LeaveCriticalArea(); if (criticalarea) { ClientManager.EnterCriticalArea(); } }