C# MySql Dapper

using System.Text.Json;
using MySql.Data.MySqlClient;
using Dapper;
using System.IO;


static void MySQLDemo() { string selectSQL = "select * from salesorderdetail;"; string connString = "Server=localhost;Port=3306;Database=mydb;Uid=root;Pwd=Root;"; using (MySqlConnection conn=new MySqlConnection(connString)) { conn.Open(); var result=conn.Query<dynamic>(selectSQL); string jsonValue = JsonSerializer.Serialize(result); StreamWriterContent("DapperJson2.txt", jsonValue); } } static void StreamWriterContent(string filePath,string content) { using (StreamWriter msgWriter = new StreamWriter(filePath, true, Encoding.UTF8)) { msgWriter.WriteLine(content); } }

 

posted @ 2020-11-24 20:50  FredGrit  阅读(446)  评论(0编辑  收藏  举报