Click here to Skip to main content
15,900,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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);

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

please help.
Updated 27-May-14 9:40am
[no name] 27-May-14 15:43pm    
Help with what? If you want to use SqlConnection then you have to change your OleDbConnection to SqlConnection.

1 solution

" 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;

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900