Connecting to a database in Visual Studio 2015

This will be a simple / stupid question.

I installed Visual Studio 2015 Enterprise and created a class library project with Framework 4.6. But I can not find [System.Data].

I want to connect to a SQL server using SqlConnectionand SqlCommandas an object. IntelliSense is not working. I can not find an example on Google. Every example I found is related to framework 4.0. But I'm used to working with Visual Studio 2010.

enter image description here

:
, , web → Class library, Windows → Class Library, . ... , -. NewBLL >= 1.0.0- * .

+4
3

System.Data.

:

using System.Data.SqlClient;

+2

, Google... , . , , , .

SqlClient, , , System.Data, System.Data.SqlClient.

using System.Data.SqlClient;

( , ), , . SqlConnection SqlCommand.

SqlConnection - , . , , , :

SqlConnection connection = new SqlConnection();

, ConnectionString. , object using, :

using(SqlConnection connection = new SqlConnection()) 
{

} //<--object is disposed of at the end of the code block.

using https://msdn.microsoft.com/en-us/library/yh598w02.aspx, IDisposable https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx .

, SqlCommand object, ... well using statement:

using(SqlConnection connection = new SqlConnection())
{
    using(SqlCommand command = new SqlCommand())
    {

    }
}

SqlCommand , SQL Server. , :

command.ExecuteNonQuery();

, , , , .

SqlConnection Class https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(v=vs.110).aspx

SqlCommand Class https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand(v=vs.110).aspx

ConnectionString https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx

0

Make sure you add the regular class Library not class Library (package)

Class library

0
source

Source: https://habr.com/ru/post/1648885/


All Articles