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

Posted win32pro

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用C#的DAPPER 进行增删改查操作(准备工作)相关的知识,希望对你有一定的参考价值。

如何在C#中使用Dapper ORM从SQL数据库插入,更新,删除和查看学生资料数据

步骤1: 单击 新建项目,然后选择左侧的Visual C#,然后点选windows ,然后选择 Windows窗体应用程序。命名您的项目“ CRUD”,然后单击 确定

技术图片技术图片

 选择“类库”,然后创建CRUD.Core和CRUD.DataAccess项目

技术图片

步骤2:您需要将dapper安装到CRUD.DataAccess项目,右键点击您的项目,选择Manage NuGet Packages->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]

插入测试数据

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‘);

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

 

以上是关于使用C#的DAPPER 进行增删改查操作(准备工作)的主要内容,如果未能解决你的问题,请参考以下文章

C# Dapper 基本使用 增删改查事务等

在C#的控制台应用中使用Dapper链接MySQL并执行一些增删改查

Dapper基本增删改查

json-server对数据进行增删改查操作

Zhuo笔记:使用C#链接SQL数据库并进行增删改查操作

通过JDBC进行简单的增删改查(以MySQL为例)