-1

Something seems wrong with the c# database for Accounts:

Right at the database I get the error message of:

Error 1 The type or namespace name 'Connection' could not be found (are you missing a using directive or an assembly reference?)

What am I possibly doing wrong with it? I would like to connect to the database in the Accounts

http://puu.sh/hiYKZ/01e0da1578.png

code:-

    public SQLConnection acctsConnect(){
        try{
            Class.forName("C:\\ChattBankMDB.mdb");
        }catch(ClassNotFoundException e){
            Console.WriteLine("Error: " + e);
        }

        SQLConnection connect = null;

        try{
            connect = DriverManager.getConnection("C:\\ChattBankMDB.mdb");
        }catch(SQLException e){
            Console.WriteLine("Error: " + e);
        }

        return connect;
    }
    }
}
Hiy
  • 405
  • 1
  • 4
  • 8

3 Answers3

2

Your code could pass for valid c# code but the APIs you are using are wrong ... which leads me to believe it is valid java code ... database code in c# would use ADO.NET (SQLConnection, Command etc) but you are using Connection, Statement etc .. which are consistent with JDBC

Please review what you are trying to do.

scartag
  • 17,548
  • 3
  • 48
  • 52
  • Unfortunately I've taken Java for 3 semesters and should have known that was the issue (new to c#) it did not give me complete errors therefore I figured it was right. – Hiy Apr 19 '15 at 06:42
0

you can pass sqlconnection in your code and write your database path in data source.

 SqlConnection con = new SqlConnection("Data Source=TCS3\\SQLEXPRESS;Initial Catalog=Forest_DB;User ID=sa;Password=sql2008");
Shaunak D
  • 20,588
  • 10
  • 46
  • 79
0

Best solution is using ms sql server instead of access file format but your answer is: How to connect to a MS Access file (mdb) using C#?

Community
  • 1
  • 1
Ghanat
  • 158
  • 1
  • 11