MySQL DataCONnection 和 ADO.NET
我想根据条件使用 mysqlconnection、命令和数据读取器或 sqlconnection、命令和数据读取器。我想对两种类型的连接使用相同的变量
例如:
Currently i have
dim _c as New mySqlConnection()
dim _cmd as New mysqlCommand()
dim _reader as New mysqlreader()
_reader = _cmd.executereader()
'loop through _reader
-----------------
我如何更改前三个以根据选择情况使用 sql/mysql。这可能吗?
I want to use mysqlconnection, command and datareader or sqlconnection, command and datareader based on a condition. I want to use same variables for both type of connection
Ex:
Currently i have
dim _c as New mySqlConnection()
dim _cmd as New mysqlCommand()
dim _reader as New mysqlreader()
_reader = _cmd.executereader()
'loop through _reader
-----------------
How can i change first three to use sql/mysql based on select case. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是可能的。 ADO.NET 有一个用于此目的的提供程序 API。你必须做这样的事情:
Yes, it is possible. ADO.NET has a provider API for that. You have to do something like this:
编写一个返回数据读取器的方法。将您的选择案例放在方法中,无论您使用什么条件来构建查询,都将返回数据读取器。
完成后请确保关闭数据读取器。
Write a method that returns the datareader. Place your select case in the method, regardless of the conditions you use to build the query, the data reader will be returned.
Make sure you close the data reader when you are done.