简体   繁体   English

如何使用VB.Net Windows应用程序在MS Access(.mdb文件)上创建和使用存储过程

[英]How to create and use Stored Procedure on MS Access (.mdb File) with VB.Net Windows Application

My IDE is Visual studio 2008. 我的IDE是Visual Studio 2008。

I just want to ask how to create Stored Procedures in Microsoft Access Database (.mdb) and pass the values to a VB.NET Windows Application. 我只是想问一下如何在Microsoft Access数据库(.mdb)中创建存储过程并将值传递给VB.NET Windows应用程序。

Thanks for the Answer. 感谢您的回答。

i need to know: - how to create stored Procedures - how to connect to the database - how to call the stored procedure in the VB.NET Codes for windows app. 我需要知道: - 如何创建存储过程 - 如何连接到数据库 - 如何在Windows应用程序的VB.NET代码中调用存储过程。 - how to use the values in reports. - 如何使用报告中的值。

thanks in advance for the help. 先谢谢您的帮助。

The closest thing to stored procedures in access are queries. 访问中存储过程最接近的是查询。 You can follow the access help and tutorials for information on how to create one. 您可以按照访问帮助和教程获取有关如何创建一个的信息。

Once you have it created, you can access it from VB as follows: 创建后,可以从VB访问它,如下所示:

    Using conn As New OleDbConnection()
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myaccess.mdb"
        conn.Open()
        Using cmd As New OleDbCommand()
            cmd.CommandText = "NameOfTheQuery"
            cmd.CommandType = CommandType.StoredProcedure
            ' Note: You can also use CommandType.TableDirect
            cmd.Connection = conn
            cmd.ExecuteNonQuery()
            conn.Close()
        End Using
    End Using

The above assumes that you have the following imports statement at the top of your code: 以上假设您在代码顶部有以下import语句:

Imports System.Data.OleDb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM