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

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

问题描述

帐户的c#数据库似乎有问题:



正在数据库我收到以下错误消息:


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


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





代码1:

  public void setCustAccounts custId){

SQLConnection connect = acctsConnect();
命令语句= null;
ResultSet result = null;
String sql =SELECT acctNo FROM Accounts其中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: - / p>

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


解决方案>

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

 使用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天全站免登陆