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); } }