MySQL查询检索数据列名 [英] MySQL Query To Retrieve Data With Column Names

查看:165
本文介绍了MySQL查询检索数据列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一些工具具有以检索所检索数据集的列名时的任何查询被施加到它

I am writing some tool which has to retrieve column names of the retrieved data set when any query is applied to it.

如果你熟悉的phpMyAdmin,你会意识到SQL窗格中做什么是它运行您的查询,显示结果与列名。我不知道如何努力,查询是,它总是导致列名的,什么是真正的幕后的节目?是不是喜欢,分析了查询,然后发现从它的表名,然后首先使用查询显示列从表名键,然后将数据检索列名?

If you're familiar with phpMyAdmin, you would realize the SQL pane does what is it runs your query and shows result with the column names. I wonder how hard the query would be, it always results in column names and what's actually the programming behind the scene? Is it like, it analyzes the query and then find table names from it and then first retrieve column names using query show columns from table-name and then the data?

有没有什么更好的办法?

Is there any better way?

更新时间: 对不起,不完全信息,我想我必须说,我使用了.NET的MySQL连接器和正在使用C#。

UPDATED Sorry for incomplete information, I think I must say I am using MySQL connector for .NET and am using C#.

推荐答案

您列DataReader的或数据表,你在C#中加载使用Metadate的一部分

Your columns are part of the metadate of the DataReader or DataTable that you load in c#

MSDN 的数据表:

private void PrintColumnNames(DataSet dataSet)
{
    // For each DataTable, print the ColumnName.
    foreach(DataTable table in dataSet.Tables)
    {
        foreach(DataColumn column in table.Columns)
        {
            Console.WriteLine(column.ColumnName);
        }
    }
}

有关一个DataReader,请参阅<一href="http://stackoverflow.com/questions/681653/can-you-get-the-column-names-from-a-sqldatareader">Can你从一个SqlDataReader得到的列名?

For a DataReader, see Can you get the column names from a sqldatareader?

这篇关于MySQL查询检索数据列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆