0

I have a DataGridView which is filled with the data that is in the table in my MySQL database. But I don't want to get all the lines.

I have for example: Name Surname E_Mail text

I want to get the title Name Surname and so on

But what I don't want is that I also get for example: Max Musterman | email@at.at | blablabal

I only want to get the Title and it should work for all tables for example if I switch the table which has only 2 columns : Computer | Cost

I want to get in my DataGridView Computer and Cost but again not the data for example HP 700€

I hope its clear what I want. But for now I get the Table title with the data and I don't want to get the data :(. Here is the code that gets me the whole table:

private void BindGrid()
{
    IPHostEntry Host = Dns.GetHostEntry(Dns.GetHostName());
    string IPAddress = Host.AddressList[1].ToString();
    // MessageBox.Show(IPAddress);
    string datasource = IPAddress;
    string database = "datenbank";
    string port = "xxx";
    string UID = "xxx";
    string pw = "xx";

    string myConnection;
    myConnection = string.Format("datasource=" + datasource + ";" + "Database=" + database + ";" + "port=" + port + ";" + "UID=" + UID + ";" + "password=" + pw);

    using (MySqlConnection con = new MySqlConnection(myConnection))
    {
        using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM Formular", con))
        {
            cmd.CommandType = CommandType.Text;
            using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd))
            {
                using (DataTable dt = new DataTable())
                {
                    sda.Fill(dt);
                    dataGridView1.DataSource = dt;
                }
            }
        }
    }
}
Becuzz
  • 6,846
  • 26
  • 39
Zezima
  • 3
  • 4
  • 1
    all lines? all columns? data? title? Shown in the grid? Please make your question shorter and clearer – DrKoch Jan 14 '15 at 11:07
  • Sorry my English is not that good. What i want is that i get the coloumn names only and that should be then displayed in Datagridview. I want ID NAME if the table contains only those 2 coloumn names. But i dont want the data for example: 1 | Thomas – Zezima Jan 14 '15 at 11:19
  • SELECT column_name FROM information_schema.columns WHERE table_name = 'your_table' i found this somewhere and tested it on mysql and it worked but how do i change the code above to make it work? – Zezima Jan 14 '15 at 11:22
  • here is an example: http://stackoverflow.com/a/368578/891715 – Arie Jan 14 '15 at 11:26
  • i replaced it with: SELECT * FROM Formular now i get what i want but can i change it i want it like this: ID Name Surname and not down down down – Zezima Jan 14 '15 at 11:27

0 Answers0