mysql - 在 VB.NET 中为 MySql 和 MSSql 编程

标签 mysql sql-server vb.net interface abstract-class

我有一个用 VB.NET 编写的程序,作为其功能的一部分,它需要使用许多数据库类。

目前,这些类被专门编程为使用源自 System.Data.SqlClient 的对象,并使用了诸如 SqlConnection、SqlCommand、SqlParameter 和 SqlDataAdapter 等类。

我的目标是使用来自 Mysql.Data.MySqlClient 的类似类(通过 MySQL 站点上的 Connector/Net 下载获得)。例如:MySqlConnection、MySqlCommand、MySqlParameter 和 MySqlDataAdapter。

代码中是否有某种方法可以指定类的抽象版本(例如 AbstractSqlCommand、AbstractSqlParameter),并能够根据其他一些配置变量的使用在 SqlCommand 和 MySqlCommand 之间选择正确的实现。

        Dim command As New AbsSqlCommand(sql, connection)
        For Each p As AbsSqlParameter In param
            command.Parameters.Add(p)
        Next
        Dim timeout As Integer = 3000
        command.CommandTimeout = timeout
        Try
            connection.Open()
        Catch
            Throw New Exception("Connection failed")
        End Try
        Dim Adapter As New AbsSqlDataAdapter(command)
        Adapter.Fill(table)
        Return table

因此在上述情况下,可以使用某种全局变量或配置变量来区分 AbsSqlCommand 实际上是用作 MySqlCommand 还是 SqlCommand [MSSQL],而无需重新编码这些对象的每个实例以适应特定的数据库平台。

最佳答案

这确实是一个广泛的问题,最好由 full article like this 回答。 , 但是看看

System.Data.Common Namespace

The classes in System.Data.Common are intended to give developers a way to write ADO.NET code that will work against all .NET Framework data providers.

关于mysql - 在 VB.NET 中为 MySql 和 MSSql 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17083518/

相关文章:

c# - 线程池饥饿

.net - 在VB.NET中使用RSA加密进行解密

java - android OkHttpClient 请求错误

mysql - 根据表中id的日期选择数据

mysql - 有没有办法在MySQL中插入字符串?

sql-server - SQL Server - 不使用别名创建计划指南

mysql - SQLite 如何知道日期列是否是当前月份

.net - Office 2003 互操作问题,未找到接口(interface)、方法

mysql - 包含用户电子邮件和密码的内置表仅允许其他用户登录

mysql - 如何将 table1 中的行与 table2 中的数据连接,其中 table2 中的所有数据都具有 table1 中的行 id