zoukankan      html  css  js  c++  java
  • C# MySQL ADO.Net Dapper query dynamic IDictionary<string,object>

    using MySql.Data.MySqlClient;
    using Dapper;
    
    static void MySqlDapperDemo()
            {
                string connString = "Server=localhost;Port=3306;Database=firstSchema;Uid=UserName;Pwd=UserPwd;";
                using (MySqlConnection conn = new MySqlConnection(connString))
                {
                    conn.Open();
                    string querySQL = "select * from firstSchema.MyTB order by age;";
                    var queryResult = conn.Query<dynamic>(querySQL).ToList();
                    int queryCount = queryResult.Count();
                    foreach(var query in queryResult)
                    {
                        var tempResult=query as IDictionary<string,object>;
                        var keys = tempResult.Keys.ToList();
                        var values = tempResult.Values.ToList(); 
                        for(int i=0;i<keys.Count;i++)
                        {
                            string rowResult = $"{keys[i]}:{values[i].ToString()},	";
                            Console.Write(rowResult);
                        }
                        Console.WriteLine();
                    }
                }  
            }

  • 相关阅读:
    Merge Two Sorted Lists
    4Sum
    Letter Combinations of a Phone Number
    3Sum Closest
    3Sum
    Longest Common Prefix
    Roman to Integer
    Integer to Roman
    Container With Most Water
    Regular Expression Matching
  • 原文地址:https://www.cnblogs.com/Fred1987/p/13948700.html
Copyright © 2011-2022 走看看