使用VB更新SQL记录

时间:2013-04-23 04:43:35

标签: sql vba vb6

我有一个包含以下SQL更新的VB代码:

UPDATE table_A SET UPD_FLG = 'N' WHERE UPD_FLG = 'Y' 

我需要在单独的变量/记录集中找出上述查询更新的行数。目前我使用选择查询来获得相同的。但有没有办法可以使用像EXECUTE这样的VB函数来实现呢?

我正在使用VB 6.0

2 个答案:

答案 0 :(得分:1)

   Set gCommand = New ADODB.Command
        gCommand.CommandType = adCmdText
        gCommand.CommandText = sSql1
        gCommand.ActiveConnection = gconDb
        gCommand.Execute (cnt)

答案 1 :(得分:0)

您可以按照以下步骤使用简单的程序:

CREATE PROCEDURE UpdateTables
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    DECLARE @RowCount1 INTEGER
    DECLARE @RowCount2 INTEGER
    DECLARE @RowCount3 INTEGER
    DECLARE @RowCount4 INTEGER

    UPDATE Table1 Set Column = 0 WHERE Column IS NULL
    SELECT @RowCount1 = @@ROWCOUNT
    UPDATE Table2 Set Column = 0 WHERE Column IS NULL
    SELECT @RowCount2 = @@ROWCOUNT
    UPDATE Table3 Set Column = 0 WHERE Column IS NULL
    SELECT @RowCount3 = @@ROWCOUNT
    UPDATE Table4 Set Column = 0 WHERE Column IS NULL
    SELECT @RowCount4 = @@ROWCOUNT

    SELECT @RowCount1 AS Table1, @RowCount2 AS Table2, @RowCount3 AS Table3, @RowCount4 AS Table4
END

<强>参考:

Return number of rows affected by UPDATE statements

How can I get the number of records affected by a stored procedure?

在VB中使用此过程:

http://www.dbforums.com/microsoft-sql-server/993294-how-get-return-value-number-rows-affected-update-command.html