简体   繁体   English

从ASP.NET 4.0中的SQL Server 2005检索数据

[英]Retrieve data from SQL Server 2005 in ASP.NET 4.0

I'm writing a class to abstract away the stored procedures, but am stuck on the basics of opening a connection to the database. 我正在编写一个类来抽象出存储过程,但我仍然坚持打开与数据库的连接的基础知识。

Examples I've seen use the SqlConnection class, which is what I intend to do, however, I don't seem to find it in the System.Data namespace. 我见过的示例使用SqlConnection类,这是我打算做的,但是,我似乎没有在System.Data命名空间中找到它。

I think this might be a configuration/setup issue. 我认为这可能是配置/设置问题。 I'm using Visual Web Developer to write this. 我正在使用Visual Web Developer来编写它。

Is there a way to fix this, or should I switch to a "proper" version of Visual Studio? 有没有办法解决这个问题,还是应该切换到Visual Studio的“正确”版本?

You need to add System.Data.SqlClient for SqlConnection 您需要为SqlConnection添加System.Data.SqlClient

Try: 尝试:

using System.Data;
using System.Data.SqlClient;

// Use SqlConnection now

The only thing that would make that happen is if you do not have the appropriate references to the assembly concerned. 唯一能使这种情况发生的是你没有对相关程序集的适当引用。 Please check to make sure that the assembly reference to System.Data has been added to your solution and also you have imported the system.Data.SqlClient namespace in to your class file. 请检查以确保已将System.Data的程序集引用添加到解决方案中,并且还已将system.Data.SqlClient命名空间导入到类文件中。 This should solve your issue. 这应该可以解决您的问题。

VWD is just fine for what you are doing. VWD对你正在做的事情很好。 Ensure that your connection string is correct, and as kd7 said you need the System.Data.SqlClient namespace. 确保您的连接字符串正确,并且kd7表示您需要System.Data.SqlClient命名空间。

Visual Web Developer, Visual C#/VB, Visual Studio (full versions), they can all utilize this namespace. Visual Web Developer,Visual C#/ VB,Visual Studio(完整版),他们都可以使用这个命名空间。

使用System.Data.SqlClient命名空间而不是System.Data

此外,请确保您的项目中有System.Data引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM