本文介绍了在 ADO.NET 中使用 Command.Prepare 的 VBA 等效项是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 VBA 中使用 Command.Prepare 和 Command.ExecuteNonQuery?

Is there a way to use Command.Prepare, and Command.ExecuteNonQuery in VBA?

以下关于 ADO.NET 的文章中标题为考虑使用 Command.Prepare"的部分描述了类似于 ADODB 属性和方法的对象和方法,我想知道是否有 VBA 的等效项.

The section entitled "Consider Using Command.Prepare" in the following article on ADO.NET describes objects and methods that are similar to ADODB properties and methods and I am wondering if there is an equivalent for VBA.

ADODB 有 .Command、.Prepared 和 .Parameters.Append,但我似乎无法以与文章中的示例代码类似的方式将它们组合在一起.

ADODB has .Command, .Prepared, and .Parameters.Append, but I can't seem to put them together in a way that works similar to the sample code in the article.

http://msdn.microsoft.com/en-us/library/ms998569.aspx#scalenetchapt12_topic11

谢谢!

推荐答案

一旦我掌握了所有的语法,答案就变得相当简单了.不幸的是,事实证明使用 Command.Prepared 根据这篇文章没有太大优势:

The answer turned out to be fairly straightforward once I got all the syntax down. Unfortunately, it turns out there isn't much advantage to using Command.Prepared according to this article:

http://msdn.microsoft.com/en-us/library/aa260835%28VS.60%29.aspx

阅读标题为所谓的准备好的财产"的部分.

Read the section entitled the "so-called prepared property."

这是代码.使用和不使用 .Prepared = True

Here's the code. It works the same with and without .Prepared = True

With objCommand

    .ActiveConnection = ADO.Connection
    .Prepared = True
    .CommandText = "INSERT INTO [table1] ( col1 ) VALUES ( ?, ? )"
    .Parameters.Append .CreateParameter("intVariable", adInteger, adParamInput)
    .Parameters.Append .CreateParameter("strVariable", adVarChar, adParamInput)

    For intCounter = 0 To 10
        .Parameters("intVariable").Value = intCounter
        .Parameters("strVariable").Value = "test_value"
        .Execute
    Next intCounter

End With

我希望能显着减少上传数据所需的时间(有很多),但我真正得到的只是更好地利用参数.

I was hoping for a significant reduction in the time it took to upload my data (there is a lot of it), but all I really got was better use of parameters.

这篇关于在 ADO.NET 中使用 Command.Prepare 的 VBA 等效项是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:43