如何在C#中使用Dapper ORM从SQL数据库插入,更新,删除和查看学生资料数据
首先准备测试数据
创建数据表
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');
步骤1: 单击 新建项目,然后选择左侧的Visual C#,然后点选windows ,然后选择 Windows窗体应用程序。命名您的项目“ CRUD”,然后单击 确定