当我有汇编引用和using子句时,为什么找不到我的SqliteConnection? [英] Why is my SqliteConnection not found when I DO have the assembly reference AND the using clause?

查看:438
本文介绍了当我有汇编引用和using子句时,为什么找不到我的SqliteConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到无法找到类型或命名空间名称'SqliteConnection'(您是否缺少using指令或汇编引用?)这段代码:



 使用(SqliteConnection con =  new  SqliteConnection( HHSUtils.GetDBConnectionStrSite(paddedSiteNum))





...即使我的项目参考文献中有System.Data.SQLite,我也是得到:



 使用 System.Data.SQLite; 
使用 System.Data.SQLite.Generic;





..在源代码中。



什么给出?这是Visual Studio 2008中的Windows CE项目。

解决方案

< blockquote>这只是因为C#区分大小写,并且类型的正确名称是 SQLiteConnection

http://www.devart.com/dotconnect/sqlite/docs/Devart.Data.SQLite~Devart.Data.SQLite .SQLiteConnection.html [ ^ ]。



顺便说一句,使用using子句是可选的,并不真正涉及到使用一些程序集,通过引用它来定义。这就是你可以命名装配级别类型的方式,无论是什么装配;例如,它同样适用于相同的组件。 使用条款恰好缩短了一些正在使用的名称。







其实所有的功劳都应归功于PIEBALDconsult,他在对这个问题的评论中几乎写了相同的内容;我刚刚发现这个答案之后就注意到了。



-SA


I'm getting "The type or namespace name 'SqliteConnection' could not be found (are you missing a using directive or an assembly reference?)" on this line of code:

using (SqliteConnection con = new SqliteConnection(HHSUtils.GetDBConnectionStrSite(paddedSiteNum))



...even though I have System.Data.SQLite in my project's References, and I've got:

using System.Data.SQLite;
using System.Data.SQLite.Generic;



...in the source.

What gives? This is a Windows CE project in Visual Studio 2008.

解决方案

This is just because C# is case-sensitive, and correct name of the type is SQLiteConnection:
http://www.devart.com/dotconnect/sqlite/docs/Devart.Data.SQLite~Devart.Data.SQLite.SQLiteConnection.html[^].

By the way, the use of "using" clause is optional and does not really relate to the use of some assembly, which is defined by referencing it. It's just about the way you can name assembly-level types, no matter in what assembly; it equally apply to the same assembly, for example. The "using" clause just happens to shorten some names in use.

[EDIT]

Actually, all credit should go to PIEBALDconsult, who wrote nearly the same in his comment to the question; I just noticed that only after I already posted this answer.

—SA


这篇关于当我有汇编引用和using子句时,为什么找不到我的SqliteConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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