ADO.NET是.NET Framework用于访问数据的组件。其优点是可以离线操作数据库,可以减少应用程序对服务器资源的占用,提高应用程序的效率。
ASP.NET通过ADO.NET操作数据库。
ADO.NET包含两大核心控件:1).NET Framework数据提供程序 2)DataSet数据集
ADO.NET处理数据库的步骤实现: 1)连接到数据库
2)连接到数据源
3)从数据源读取数据
4)对数据进行处理
实现对数据的读取和CRUD处理
1.使用Command对象+DataReader对象
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
使用Command命令
//连接数据库
string mycon = "data source=LAPTOP-OUL99L1B;database=student;Trusted_Connection=True";
SqlConnection conn = new SqlConnection(mycon);
SqlCommand mycom = new SqlCommand(); //创建command对象