GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Blog/NETCoreMySQL/src/NETCoreMySQL/Program.cs at master · linezero/Blog Expand file tree/ Copy pathProgram.csMore file actions 42 lines (41 loc) · 1.64 KB / Copy pathProgram.csFile metadata and controls42 lines (41 loc) · 1.64 KB 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. |