Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# select data with colum title mysql

Posted on 2010-11-29
1
Medium Priority
?
605 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

670 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