使用C#的DAPPER 进行增删改查操作(准备工作)

男儿欲遂平生志,五经勤向窗前读。这篇文章主要讲述使用C#的DAPPER 进行增删改查操作(准备工作)相关的知识,希望能为你提供帮助。
如何在C#中使用Dapper ORM从SQL数据库插入,更新,删除和查看学生资料数据
步骤1: 单击 新建项目,然后选择左侧的Visual C#,然后点选windows ,然后选择 Windows窗体应用程序。命名您的项目“ CRUD” ,然后单击 确定

使用C#的DAPPER 进行增删改查操作(准备工作)

文章图片
使用C#的DAPPER 进行增删改查操作(准备工作)

文章图片

  选择“ 类库” ,然后创建CRUD.Core和CRUD.DataAccess项目
使用C#的DAPPER 进行增删改查操作(准备工作)

文章图片

步骤2:您需要将dapper安装到CRUD.DataAccess项目,右键点击您的项目,选择Manage NuGet Packages-> Dapper
使用C#的DAPPER 进行增删改查操作(准备工作)

文章图片

步骤4:您应该创建一个新的数据库,然后将一个学生表添加到数据库中
创建数据表
CREATE TABLE [dbo].[UserInfo]( [Id] [int] IDENTITY(1,1) NOT NULL, [FirstName] [nvarchar](50) NULL, [LastName] [nvarchar](50) NULL, [Email] [nvarchar](50) NULL, [Gender] [nvarchar](50) NULL, [IpAddress] [nvarchar](50) NULL, CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX= OFF, STATISTICS_NORECOMPUTE= OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS= ON, ALLOW_PAGE_LOCKS= ON) ON [PRIMARY] ) ON [PRIMARY]

【使用C#的DAPPER 进行增删改查操作(准备工作)】插入测试数据
insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Sigfrid‘, ‘Mardee‘, ‘smardee0@yellowpages.com‘, ‘Male‘, ‘240.130.149.124‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Adair‘, ‘McCulley‘, ‘amcculley1@wunderground.com‘, ‘Male‘, ‘117.91.155.101‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Archibald‘, ‘Le Port‘, ‘aleport2@goo.gl‘, ‘Male‘, ‘71.216.30.7‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Antonin‘, ‘Burling‘, ‘aburling3@imgur.com‘, ‘Male‘, ‘40.52.235.204‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Lyndsay‘, ‘Lillie‘, ‘llillie4@nytimes.com‘, ‘Female‘, ‘226.133.26.233‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Dorice‘, ‘Nijssen‘, ‘dnijssen5@list-manage.com‘, ‘Female‘, ‘17.234.233.192‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Fay‘, ‘Card‘, ‘fcard6@ycombinator.com‘, ‘Female‘, ‘86.128.82.43‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Alicea‘, ‘Bellhanger‘, ‘abellhanger7@cbsnews.com‘, ‘Female‘, ‘231.167.15.120‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Carine‘, ‘Brisse‘, ‘cbrisse8@europa.eu‘, ‘Female‘, ‘18.31.36.220‘); insert into UserInfo (FirstName, LastName, Email, Gender, IpAddress) values (‘Amii‘, ‘Sultan‘, ‘asultan9@weather.com‘, ‘Female‘, ‘64.193.222.168‘);

  创建一个存储过程以插入数据,并将数据更新到学生表
 

    推荐阅读