类型或命名空间名称'的SQLConnection'找不到 [英] The type or namespace name 'SQLConnection' could not be found

查看:236
本文介绍了类型或命名空间名称'的SQLConnection'找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些东西似乎错了账户的C#数据库:



右键在数据库中,我得到的错误消息:




错误1类型或命名空间名称'连接'找不到
(是否缺少using指令或程序集引用?)




什么我可能做错了呢?我想连接到数据库中的帐户





代码1:

 公共无效setCustAccounts(字符串CUSTID){

的SQL​​Connection连接= acctsConnect();
命令语句= NULL;
的ResultSet结果= NULL;
字符串SQL =SELECT acctNo从户口所在CID ='+ CUSTID +;

尝试{
语句= connect.createStatement();
结果= Statement.executeQuery的(SQL);


而(result.next()){
result.getRow();
账户ACCT =新帐户(result.getString(acctNo));
custAccounts.add(ACCT);
}
}

终于{
connect.close();
}
}



代码: -

 公开的SQLConnection acctsConnect(){
尝试{
的Class.forName(C:\\ ChattBankMDB.mdb);
}赶上(ClassNotFoundException异常五){
Console.WriteLine(错误:+ E);
}

的SQLConnection连接= NULL;

尝试{
连接=的DriverManager.getConnection(C:\\ChattBankMDB.mdb);
}赶上(的SQLException五){
Console.WriteLine(错误:+ E);
}

返回连接;
}
}
}


解决方案

您缺少使用指令语句在你的代码。

 使用System.Data.SqlClient的; 


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

Code 1:

 public void setCustAccounts(String custId) {

        SQLConnection connect = acctsConnect();
        Command statement = null;
        ResultSet result = null;
        String sql = "SELECT acctNo FROM Accounts Where Cid = '" + custId + "';";

        try{
            statement = connect.createStatement();
            result = statement.executeQuery(sql);


            while (result.next()){
                result.getRow();
                Account acct = new Account(result.getString("acctNo"));
                custAccounts.add(acct);                
            }
        }

        finally {
            connect.close();
        }
    }

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

解决方案

You are missing the using Directive statement in your code.

using System.Data.SqlClient;

这篇关于类型或命名空间名称'的SQLConnection'找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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