c# select data with colum title mysql

Posted on 2010-11-29
Last Modified: 2012-05-10
i just put this code  for create column title in first line it not work please help

 for (int i = 0; i < Reader.FieldCount; i++)
                string headlist = "";
                headlist += Reader.GetValue(i).ToString() + ",";


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using MySql.Data.MySqlClient;

using System.Web;

namespace WindowsFormsApplication1



    public partial class Form1 : Form


        public Form1()





        private void Form1_Load(object sender, EventArgs e)



        private void button1_Click(object sender, EventArgs e)


            string MyConString = "SERVER=localhost;" +

                "DATABASE=webboard;" +

                "UID=root;" +


            MySqlConnection connection = new MySqlConnection(MyConString);

            MySqlCommand command = connection.CreateCommand();

            MySqlDataReader Reader;

            command.CommandText = "Select * from faxcomplete limit 20 ";


            Reader = command.ExecuteReader();


            for (int i = 0; i < Reader.FieldCount; i++)



                string headlist = "";

                headlist += Reader.GetValue(i).ToString() + ",";



            while (Reader.Read())


                string thisrow = "";

                for (int i = 0; i < Reader.FieldCount; i++)

                    thisrow += Reader.GetValue(i).ToString() + ",";


                System.IO.File.AppendAllText(@"C:\file.txt", thisrow + Environment.NewLine);






Open in new window

Question by:teera
1 Comment
LVL 75

Accepted Solution

käµfm³d   👽 earned 500 total points
ID: 34236258
This looks to be my fault. The code I gave was to show HOW to retrieve the column name--you still have to do something to display it. GetName() returns a string that is the column name at index [i]i[/i]. You need to capture that value and then display it wherever you intend it to go. For example:

    string colName = Reader.GetName(i);

Please don't feel as though you have to accept the first answer you are given for a particular question. If something is unclear, feel free to ask for a clarification or to wait for another expert to participate. :)

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different Delete Messages 7 37
New to SOAP and need some direction 10 40
Combine two datatables into one based on a value from second datatable 4 32
ASP.NET 5 Templates 2 64
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now