在OLEDB连接上的Byref和byval - 一个快速的问题 [英] Byref and byval on a OLEDB connection - a quick question

查看:80
本文介绍了在OLEDB连接上的Byref和byval - 一个快速的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否正确地假设:

(例如):如果我们有一个名为DB的变量作为oledb.oledbconnection



我希望将该连接传递给我的项目模块中的另一个函数,接收子/函数具有



testfunction(byval DB as oledb.oledbconnection )

表示testfunction创建一个新连接,而



testfunction(byref DB as oledb.oledbconnection)

会使用我项目中其他地方开设的现有连接吗?



谢谢!



我尝试了什么:



好​​奇了解如何在应用程序中传递连接所以我最大限度地减少了我对一个连接的连接数量数据库

Am I right in assuming that:
(for example): If we have a variable called "DB" as a oledb.oledbconnection

and I wanted to pass that connection to another function in a module in my project that the receiving sub/function has

testfunction(byval DB as oledb.oledbconnection)
means that "testfunction" creates a new connection while

testfunction(byref DB as oledb.oledbconnection)
would use the existing connection opened elsewhere in my project?

Thanks!

What I have tried:

curious in understand how a connection can be passed around in an application so i minimise the amount of connections i am making to a database

推荐答案

请参阅按值传递参数和通过引用(Visual Basic) [ ^ ]。


传递的参数是参考课。这意味着即使使用 ByVal ,也会传递一个引用,但是你得到一个引用的副本而不是引用本身(你不会得到<$ c $的副本) c> OleDBConnection 实例)。



所以问题的答案是:

使用现有连接在这两种情况下。
The passed argument is a "reference class". That means even when using ByVal, a reference is passed but you get a copy of the reference instead of the reference itself (you will not get a copy of the OleDBConnection instance).

So the answer to your question is:
The existing connection is used in both cases.


这篇关于在OLEDB连接上的Byref和byval - 一个快速的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆