Solved

c# select data with colum title mysql

Posted on 2010-11-29
1
600 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 75

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 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