/// <summary> /// execHashJson: 普通执行Sql语句 /// </summary> /// <param name="sql">要执行的sql语句</param> /// <returns></returns> public override Json execHashJson(string sql, string key) { Json hash = null; try { DBUtil.onExecSqlBefore(_CLASS, "execJsonList", sql); using (MySqlConnection sqlConn = new MySqlConnection(dbInfo.toMyConnectionString())) { sqlConn.Open(); MySqlCommand sqlComm = sqlConn.CreateCommand(); sqlComm.CommandText = sql; using (IDataReader dr = sqlComm.ExecuteReader(CommandBehavior.Default)) { hash = DBUtil.DataReaderToHashJson(dr, key); dr.Close(); } sqlConn.Close(); } } catch (Exception ex) { DBUtil.onExecSqlError(_CLASS, "execJsonList", sql, ex.Message); } return(hash); }
/// <summary> /// 执行sql语句并得到每一行是Json节点的Json对象 /// </summary> /// <param name="sql">要执行的sql语句</param> /// <returns>HashJson</returns> public Json execHashJson(string sql, string key) { Json _json = null; try { DBUtil.onExecSqlBefore(_CLASS, "execHashJson", sql); cmd.CommandText = @sql; state = ConnectionState.Executing; using (MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.Default)) { _json = DBUtil.DataReaderToHashJson(dr, key); } } catch (Exception e) { DBUtil.onExecSqlError(_CLASS, "execHashJson", sql, e.Message); } return(_json); }