SQL Server with ADO.
NET
10 Marks Answer
Introduction
[Link] is a data access technology in the .NET framework used to connect applications with
databases. It is commonly used with SQL Server to retrieve, insert, update, and delete data. [Link]
provides objects such as SqlConnection, SqlCommand, SqlDataAdapter, and DataSet to work with
SQL Server databases.
[Link] Key Objects
[Link] Object Purpose
SqlConnection Opens/closes connection to SQL Server
SqlCommand Executes SQL queries or stored procedures
SqlDataAdapter Retrieves data and fills the DataSet
DataSet Stores retrieved data in memory (disconnected)
DataView Filters and sorts data from the DataSet
Working of SQL Server with [Link]
1. The application connects to SQL Server using the SqlConnection object.
2. The SqlCommand object executes SQL queries.
3. The SqlDataAdapter retrieves data from SQL Server and fills the DataSet.
4. The DataSet stores the data temporarily in memory.
5. DataView is used to filter and sort the data.
Example Program
The following C# program connects to a SQL Server database and retrieves student records using
[Link]:
using System;
using [Link];
using [Link];
class Program
{
static void Main()
{
string con = "Data Source=.;Initial Catalog=StudentDB;Integrated Security=True";
SqlConnection cn = new SqlConnection(con);
string query = "SELECT * FROM Student";
SqlDataAdapter da = new SqlDataAdapter(query, cn);
DataSet ds = new DataSet();
[Link](ds, "Student");
foreach (DataRow row in [Link]["Student"].Rows)
{
[Link](row["Id"] + " " + row["Name"]);
}
}
}
Explanation
• SqlConnection → Connects the application to the SQL Server database.
• SqlDataAdapter → Retrieves data from SQL Server using the query.
• DataSet → Stores the retrieved data in memory (disconnected model).
• Fill() → Fills the DataSet with data fetched from the database.
• DataRow → Used to access individual rows in the table.
Advantages
• Easy connection between application and SQL Server
• Supports data retrieval and manipulation (INSERT, UPDATE, DELETE)
• Provides both connected and disconnected architecture
• Efficient and secure database access using parameterized queries
• DataSet allows working with data even after connection is closed
Conclusion
Thus, [Link] helps applications communicate with SQL Server databases efficiently using objects
like SqlConnection, SqlCommand, SqlDataAdapter, and DataSet. It supports both connected and
disconnected models, making it a reliable choice for database-driven .NET applications.