ADO.NET Tutorial - Connecting to Data

This tutorial introduces the fundamental concepts of connecting to data sources in ADO.NET.

Learn how to establish connections to SQL Server, Oracle, and other databases.

ADO.NET

Connecting to Data

Introduction

ADO.NET is a .NET library for connecting to a variety of databases. It allows you to read and write data to these databases using C#.

Connecting to SQL Server

This example demonstrates connecting to a SQL Server database. You'll need a SQL Server instance running and accessible.

Connection String: Server=yourserver.database.windows.net;Database=yourdatabase;User Id=youruser;Password=yourpassword

Connecting to Oracle

This example connects to an Oracle database. Ensure you have the Oracle client software installed.

Connection String: User ID=youruser;Password=yourpassword;DBMS_SQL='SELECT * FROM yourtable';

Connecting to Data

This section demonstrates a basic example of connecting to a data source using the ADO.NET library.

We will create a simple sample data set.

Create a new C# class that inherits from DataAnnotations

Add some sample data in the sample data class.