Solved

c# mysql get head of table

Posted on 2010-11-29
5
375 Views
Last Modified: 2012-05-10
the code be low how can i get the head of the table
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()

        {

            InitializeComponent();

        }



        private void Form1_Load(object sender, EventArgs e)

        {



        }



        private void button1_Click(object sender, EventArgs e)

        {

            string MyConString = "SERVER=localhost;" +

                "DATABASE=registration;" +

                "UID=root;" +

                "PASSWORD='';";

            MySqlConnection connection = new MySqlConnection(MyConString);

            MySqlCommand command = connection.CreateCommand();

            MySqlDataReader Reader;

            command.CommandText = "select * from teera";

            connection.Open();

            Reader = command.ExecuteReader();

            while (Reader.Read())

            {

                string thisrow = "";

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

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

                listBox1.Items.Add(thisrow);

            }

            connection.Close();



        }

    }

}

Open in new window

0
Comment
Question by:teera
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
What do you mean by "the head of the table?"
0
 

Author Comment

by:teera
Comment Utility
Hi kaufmed
 
   I mean column

    such as Id  Name Address
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
I think you mean the field names. For that, use:
for (int i = 0; i < Reader.FieldCount; i++)
{
    // Reader.GetName(i);
}

Open in new window

0
 

Author Comment

by:teera
Comment Utility
Hi kaufmed
 
 I mean column title



0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
>>   I mean column title

That's what the code I posted should give you  :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

17 Experts available now in Live!

Get 1:1 Help Now