使用c#连接访问数据库 [英] connect access DB with c#

查看:63
本文介绍了使用c#连接访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb 2010 ultimate c#。

i找不到此提供商 Microsof Jet 4.0 ILE DB提供程序

i尝试过连接访问数据库与我的项目,但我有问题使用此 OleDbDataAdapter



我该怎么办?

i''m using vb 2010 ultimate c#.
i can''t find this provider Microsof Jet 4.0 ILE DB Provider
i tried to connect access db with my project but i have problem using this OleDbDataAdapter

how can i do it?

推荐答案

假设您只需要正确的连接字符串语法,请在此处查看: http:// www。 connectionstrings.com/access-2007 [ ^ ]。



从这个简短的教程开始: http://www.dscripts.net/2009/01/20/connect-to-microsoft-access-mdb-database-using-csharp/



以下是此主题的截屏视频: http://www.youtube .com / watch?v = uw9vVvgqVMk [ ^ ]
Supposing you need only the proper connection string syntax, look around here: http://www.connectionstrings.com/access-2007[^].

Start with this short tutorial: http://www.dscripts.net/2009/01/20/connect-to-microsoft-access-mdb-database-using-csharp/

Here is a screencast in this topic: http://www.youtube.com/watch?v=uw9vVvgqVMk[^]


也许你说的是这样的......



maybe you are saying something like this..

Provider=Microsoft.Jet.OLEDB.4.0;Data Source= ''your database path.


两种连接到Access数据库的方法



1)视觉上,使用设计时工具。

2)以编程方式。



以编程方式:

在项目中包含这些名称空间:

There are two ways to connect to an Access database:

1)Visually, with design-time tools.
2)Programmatically.

Programmatically:
include these namespaces in your project:
using System.Data;
using System.Data.OleDb;







并有一个字符串连接示例:




and have a example for string connection:

public void Accessdata()
{
    System.Data.OleDb.OleDbConnection conn = 
                                     new System.Data.OleDb.OleDbConnection();

    conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
        @"Data source= C:\Documents and Settings\username\" +
        @"My Documents\AccessFile.mdb"; // connection string 
    try
    {
        conn.Open();
        // Insert code for operations.
    }
        catch (Exception ex)
    {
        MessageBox.Show("Failed to connect to data source");
    }
    finally
    {
        conn.Close();
    }





视觉上,使用设计时工具



创建与Access数据库的连接 [ ^ ]


这篇关于使用c#连接访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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