Solved

c# select data with colum title mysql

Posted on 2010-11-29
1
596 Views
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++)
            {
                Reader.GetName(i);
                string headlist = "";
                headlist += Reader.GetValue(i).ToString() + ",";
                listBox1.Items.Add(headlist);

            }


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=webboard;" +

                "UID=root;" +

                "PASSWORD='';";

            MySqlConnection connection = new MySqlConnection(MyConString);

            MySqlCommand command = connection.CreateCommand();

            MySqlDataReader Reader;

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

            connection.Open();

            Reader = command.ExecuteReader();

            

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

            {

                Reader.GetName(i);

                string headlist = "";

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

                listBox1.Items.Add(headlist);



            }





            while (Reader.Read())

            {

                string thisrow = "";

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

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

           listBox1.Items.Add(thisrow);

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

            }

            connection.Close();



        }

    }

}

Open in new window

0
Comment
Question by:teera
1 Comment
 
LVL 74

Accepted Solution

by:
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. :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

20 Experts available now in Live!

Get 1:1 Help Now