c# and sql server
c# and sql server
.NET Framework
The .NET Framework is a software development framework developed by Microsoft. It
provides a controlled environment for developing and running applications on Windows.
Key features of the .NET Framework include:
- Common Language Runtime (CLR): Executes .NET programs and provides services
like memory management, type safety, exception handling, and garbage collection.
- Base Class Library (BCL): Provides a comprehensive set of classes and interfaces that
provide a wide range of functionalities such as file I/O, data access, cryptography, web
application development, numeric algorithms, and network communications.
SqlConnection
`SqlConnection` is a class in the .NET Framework's `System.Data.SqlClient` namespace.
It represents a connection to a SQL Server database. It is used to open a database
connection and execute commands against the database.
using System.Data.SqlClient;
SqlConnection conn = new SqlConnection("your_connection_string");
conn.Open();
// Perform database operations
conn.Close();
SqlDataAdapter
`SqlDataAdapter` is a class that serves as a bridge between a `DataSet` and a SQL Server
database for retrieving and saving data. It uses `SqlCommand` objects to execute SQL
commands. It is commonly used to fill a `DataSet` with data from a database and to
update the database with changes made in the `DataSet`.
//conn your sql connection
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM your_table", conn);
adapter.Fill(ds);
SqlCommand
`SqlCommand` is a class that represents a SQL statement or stored procedure to execute
against a SQL Server database. It is used to execute queries, commands, or stored
procedures.
SqlCommand command = new SqlCommand("SELECT * FROM your_table", conn);
SqlDataReader reader = command.ExecuteReader();
ExecuteNonQuery
`ExecuteNonQuery` is a method of the `SqlCommand` class that executes a SQL
command that does not return any results. It is typically used for executing SQL
statements like `INSERT`, `UPDATE`, `DELETE`, and DDL (Data Definition
Language) commands.
DataSet
`DataSet` is a class that represents an in-memory cache of data. It is a collection of
`DataTable` objects and can be used to manage and manipulate data from multiple
sources.
DataSet ds = new DataSet();
adapter.Fill(ds);
DataTable
`DataTable` is a class that represents one table of in-memory data. It is part of the
`DataSet` and can be used independently. A `DataTable` consists of rows and columns.