在VS 2005中设计数据库连接类

发布于 2024-09-29 12:41:25 字数 159 浏览 3 评论 0原文

我正在 VB.net 2005 中设计一个 SQL Server 数据库连接类。这样做的想法是,开发人员可以调用该类,将存储过程名称与参数一起传递给它,并获取返回值(如果有的话)。

我的问题是,如何设计该类以使存储的过程参数是动态的? 我的第二个问题是,如何解释传递给存储过程的数据类型?

I am working on designing a SQL Server database connection class in VB.net 2005. The idea behind doing this will be so a developer can can call the class, pass it a stored procedure name along with the parameters, and get return values back (if any).

My question is, how would I design the class so the stored proc parameters are dynamic?
My second question is, how would I account for the data type being passed to the stored procedure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞清仓 2024-10-06 12:41:25

这里假定 SQL Server,但可以更改 SqlParameter 类型以匹配连接类型。当项目添加到此列表时,必须识别数据类型。

    Imports System.Data.SqlClient
    Dim Params As List(Of SqlParameter)

    Public Property ParameterList() As List(Of SqlParameter)
        Get
            Return Params
        End Get
        Set(ByVal value As List(Of SqlParameter))
            Params = value
        End Set
    End Property

您必须循环遍历列表并将每个参数添加到命令对象。

This assumes SQL Server, but the SqlParameter type could be changed to match the connection type. As items are added to this list the data type would have to be identified.

    Imports System.Data.SqlClient
    Dim Params As List(Of SqlParameter)

    Public Property ParameterList() As List(Of SqlParameter)
        Get
            Return Params
        End Get
        Set(ByVal value As List(Of SqlParameter))
            Params = value
        End Set
    End Property

You'll have to loop through the list and add each parameter to a command object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文