如何将Oledb连接更改为Sql连接 [英] How Do I Change Oledb Connection To Sql Connection

查看:202
本文介绍了如何将Oledb连接更改为Sql连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有ms访问数据库的项目,但是以某种方式我将ms访问数据库转换为sql server db.但是问题是我想将sql db连接到该项目而不是访问db.我该怎么做.

演示在这里:

i have a project with the ms access database but somehow i convert that ms access db to sql server db.but the problem is that i want to connect the sql db to that project instead of access db.how can i do that.

a demo is here:

OleDbDataReader dr;
    OleDbConnection con;

    //Static Variables to count Number of Total Questions
    static int totalQuest, sel_ans = 0, totalmarks = 0;

    public void connect()
    {
        string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
        con = new OleDbConnection(CS);



在这里它使用oledb名称,但是我想使用SqlConnection con = new SqlConnection();

请帮忙.



here it uses the oledb name,but i want to use SqlConnection con = new SqlConnection();

please help.

推荐答案

我要使用SqlConnection con = new SqlConnection();"

不,你没有.您要使用IDbConnection = new SqlConnection();
使用接口而不是具体的类将帮助您更轻松地进行此类更改.

因此,将您的字段更改为:

" i want to use SqlConnection con = new SqlConnection();"

No, you don''t. You want to use IDbConnection = new SqlConnection();
Using the interfaces, rather than the concrete classes, will help you make such changes much easier.

So change your fields to:

IDataReader dr;
IDbConnection con;



请参阅:通过ADO.NET接口简化的数据库访问 [ ^ ]



See: Simplified Database Access via ADO.NET Interfaces[^]


这篇关于如何将Oledb连接更改为Sql连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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