GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Blog/NETCoreMySQL/src/NETCoreMySQL/Program.cs at master · linezero/Blog

Expand file tree

/

Program.cs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
42 lines (41 loc) · 1.64 KB
/

Program.cs

Copy path

File metadata and controls

42 lines (41 loc) · 1.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using System.Text;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace NETCoreMySQL
{
public class Program
{
public static void Main(string[] args)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
MySqlConnection con = new MySqlConnection("server=127.0.0.1;database=test;uid=root;pwd=;charset='gbk';SslMode=None");
//新增数据
con.Execute("insert into user values(null, '测试', 'http://www.cnblogs.com/linezero/', 18)");
//新增数据返回自增id
var id = con.QueryFirst<int>("insert into user values(null, 'linezero', 'http://www.cnblogs.com/linezero/', 18);select last_insert_id();");
//修改数据
con.Execute("update user set UserName = 'linezero123' where Id = @Id", new { Id = id });
//查询数据
var list = con.Query<User>("select * from user");
foreach (var item in list)
{
Console.WriteLine($"用户名:{item.UserName} 链接:{item.Url}");
}
//删除数据
con.Execute("delete from user where Id = @Id", new { Id = id });
Console.WriteLine("删除数据后的结果");
list = con.Query<User>("select * from user");
foreach (var item in list)
{
Console.WriteLine($"用户名:{item.UserName} 链接:{item.Url}");
}
Console.ReadKey();
}
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.