获取网络查询结果

本文关键字:结果 查询 网络 获取 | 更新日期: 2023-09-27 18:31:29

我一直在做一些在netezza数据库上执行查询的测试过程。我只是想知道是否有办法返回任何输出,例如更新的行,或者如何捕获任何错误消息。就像现在一样,它处于正常的 try/catch 块中,但如果查询失败,它会作为异常返回,还是程序会因为没有收到错误/输出而继续?

基本上我想做的是在下面的控制台写出中,我希望它每次循环时都写出输出,然后写出错误(如果有)。例如,当我使用接口进行查询时,它只会滚动说"等等等等执行,更新了 1 行",或者在出现问题时会返回错误消息。

下面是代码:

try 
{
    netezzaConn = new OleDbConnection(connString);
    netezzaConn.Open();
    for(int i = 0; i < recordCounts.Count; i++) {
        if(recordCounts[i].RecordCount.ToString() != recordCounts[i].OrigCount.ToString()) {
            string updateStatement = myquery;
            Console.WriteLine("Executing query : " + updateStatement);
            OleDbCommand exe = new OleDbCommand(updateStatement, netezzaConn);
            exe.ExecuteNonQuery();
        } else {
            Console.WriteLine("No records were removed from the file : " + recordCounts[i].FileName + ". Not updating Netezza.");
        }
    }
    netezzaConn.Close();
}

获取网络查询结果

对此

进行了一些研究,您必须使用返回...

int 行受影响的 = 命令。执行非查询();

受影响的行将显示已更改的行数。