tags: C# sql C # Connect SQL Database
Use the SqlConNetion class. When using the SQLConnection class, you want to reference a namespace of system.data.sqlclient.
using System.Data.SqlClient;
Using the SQLCommand database command class mainly performs operations for the database, such as inserting, deleting, modifying the database.
Use SqlDataReader. Database read category is the database command class in the data type of the result returned after the query operation. Database read category is only available when the database's connection status is in an open state. When the database is closed, the database read category is no longer valid.
The data set is equivalent to a virtual database, and each data set includes multiple data sheets. Even if the database is connected, it is still possible to continue access to the record from the data set, but the data is stored in the data set and is not stored in the database.
You can use SqlDataAdapter. The data adapter is often used with the data set. The data adapter can store the data in the database to the data set, and the data adapter can be said to be a bridge between the data set and the database.



Enter your own server name here, there are two login methods, Windows and authentication logins. This is the same way as you create a database.

Again to choose the table you need to operate here.
There are two ways to connect the database(See how you log in)
Data Source = server name; Initial catalog = database name; user ID = username; PWD = password (no password can be omitted)
Column:
string connStr = "Data Source=.;Initial Catalog = MySchool;User ID = aa;Password=123";
string connStr = "Data Source=.;Initial Catalog=QQ;Integrated Security=True";

Next, you can operate the database.
The test is successful
public void TestConSQL()
{
// Test connection database
string connStr = "Data Source=.;Initial Catalog=QQ2021;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
// Open the database
conn.Open();
Console.WriteLine("Open Database Connection");
// Close the database
conn.Close();
Console.WriteLine("Close Database Connection");
}
Execute SQL statement: Command object 1. Command object overview The Command object is a data command object. Its main function is to send query, update, delete, and modify SQL statements ...
tool: 1. Visual Studio (I use vs2013) 2.SQL Server (I use sql server2008) operating: 1. Open SQL Server, and you will see the initial link interface of the database. (As shown below) 2. Copy the "...
1. Use SQL username and password authentication Data Source = server name; Initial Catalog = database name; User ID = user name; Pwd = password (no password can be omitted) E.g:public string con...
My understanding of ADO is not so thorough. So far, I feel that ADO may have the same function as JDBC and can connect to the database. At present, I only use c# to connect to sqlserver (mysql) throug...
Article Directory Necessary preparation Connection process Implementation code Use configuration files Necessary preparation To connect to the database, you must first have a database windows authenti...
Python connects to SQL Server database - pymssql uses the basics ----Original address: The following is the instructions for using the parameters in pymssql, as follows: pymssqlCnx class (used to conn...
Article Directory 1. Installation of SQL Server and SSMS Second, the connection of SQL Server 1. Installation of SQL Server and SSMS 1. SQL installation download link:SQL Server。 Enter the download ad...
Microsoft's SQL Server database is a good friend for .NET development. The latest version is now 2017. The SQL Server database has its own Management Studio tool, which is basically similar to Visual ...
1. Preparation SQL Server database installation, IDEA and JDK environment installation and configuration. I installed SQL Server 2008, the JAVA environment is as follows, IDEA is installed automatical...
When I first came into contact with using JDBC to connect to a database, I always encountered a lot of problems, making people confused. Therefore, I use SQL Server As an example, explain in detail ho...