码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2020-05-01 14:59:34      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:存储   sig   create   lis   技术   packages   aac   news   新建   

如何在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 进行增删改查操作(一、准备工作)

标签:存储   sig   create   lis   技术   packages   aac   news   新建   

原文地址:https://www.cnblogs.com/win32pro/p/12813335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!