[英]How to exact data from MySQL in readable format C#
So Day 4 in learning C#. 因此,学习C#的第4天。 I have built a data base before and can query that database using mysql workbench no issues and get the results I want. 我之前已经建立了一个数据库,可以使用mysql工作台查询该数据库而没有任何问题,并可以获得我想要的结果。 I am trying to get those results in visual studio code via C#. 我试图通过C#在Visual Studio代码中获得这些结果。 I can get as far as to pull the data and it will console write 我可以拉远数据,它将控制台写入
System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]
System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]
System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]
What I get in my Sql workbench when i run SELECT First_Name FROM users ; 当我从用户运行SELECT First_Name时,我在Sql工作台中得到什么; it gives me my first names no issues. 它使我的名字毫无问题。
But if i use 但是如果我用
public class Program
{
public static void Main(string[] args)
{
var thing = DbConnector.Query("SELECT First_Name FROM users ");
foreach(var i in thing)
{
System.Console.WriteLine(i.Values);
}
}
}
}
It gives me that system collection stuff. 它给了我系统收集的东西。
I have tried i.value, and i.value.tostring() I really just need to know what method to convert the string to the value not the object. 我已经尝试过i.value和i.value.tostring(),我真的只需要知道将字符串转换为值而不是对象的方法。
The database is sending it over like so 数据库正在像这样发送它
public static List> Query(string queryString) 公共静态列表>查询(字符串queryString)
Any Help would be greatly appricated. 任何帮助将不胜感激。
Values
is a ValueCollection
property see the docs . Values
是ValueCollection
属性, 请参阅docs 。 You will have to iterate through the values and write them to the Console if you want to see them. 如果要查看它们,则必须遍历这些值并将其写入控制台。
var thing = DbConnector.Query("SELECT First_Name FROM users ");
foreach(var i in thing)
{
foreach(var item in thing.Values)
{
System.Console.WriteLine(item.Key);
System.Console.WriteLine(item.Value);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.