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