Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MySQL .NET Gridview question

  • 10-09-2006 05:02PM
    #1
    Closed Accounts Posts: 2,585 ✭✭✭


    Hi Everyone,

    I'm new to MYSQl and .NET so hopefully comeone can help me with this. I cann't figure out how to change the column names. I have a Gridview which I am populating from a MySQL database as follows:
    // Set up connection
    MySqlConnection conn = new MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=password");

    // Data Adaptor
    MySqlDataAdapter da;

    da = new MySqlDataAdapter("SELECT name, address, phone_number from details", conn);
    DataSet ds = new DataSet();
    da.Fill( ds, "Details" );
    grd.DataSource = ds;
    grd.DataBind();

    How can I change the column names in the grid?

    Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    You can change them in either the HTML for the gridview or by right-clicking on the gridview and choosing Show Smart Tag -> Edit Columns... Select each column in the Selected fields list and set its HeaderText property.

    Google GridView Tutorial and have a look at what comes up, http://www.4guysfromrolla.com/ are always good.


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    http://www.gridviewguy.com/ is another good one. Not as comprehensive as 4guysfromrolla, but some nice little tips and tricks.


  • Registered Users, Registered Users 2 Posts: 1,464 ✭✭✭evilhomer


    You could also do it on the SQL side

    SELECT name as 'first name', address as 'customer address', phone_number as 'Phone No.' from details

    it's pretty easy on that side and keeps the VB code to a minimum.


  • Closed Accounts Posts: 2,585 ✭✭✭HelterSkelter


    Thanks for the help guys. Will give those suggestions a go.


Advertisement