locked
DataGridView Columns RRS feed

  • Question

  • In DataGridView Columns are not coming in order while accessing data from database.Please any one help me.

     

    Thanx

     

    Tuesday, February 21, 2006 6:32 AM

All replies

  • Hi there,

    Please post what columns order should your datagrid look like and include the sql query statement so that we could figure it out how you do it.
    For additional tip:
         If you are using Select * in your query statement, you need to know what would be the orders of your column before assigning it to the object datasource. You can have this format query statement instead of using the "SELECT *", use "Select OrderId,Amount,Quantity from tblCustomer".

    Hth,

    Michael Castillones

     

     

    Tuesday, February 21, 2006 3:21 PM
  • Dear Michael ,

    I have got table "Employee" having fields as

    SSN | Name | First Address | Second Address | Phone | Introduced People.

    While accessing this data in my project in DataGridView this is coming in following order

    Phone  | Name |  Introduced People | Second Address |SSN | First Address .

    The query which i have written is as following

    Select    SSN , Name , First Address , Second Address , Phone , Introduced People

    From     Employee

     

     

    Vinod Kumar

     

    Wednesday, February 22, 2006 12:06 PM
  • Hi,

    There must be something strange in your database. Are you using MSSQL Server Database? If your using it, try this 2 options to find out what's wrong with your problem.

    1.) Try to test your query in the Query Analyzer. So that you could see the order of your columns. What would be the order of the columns which are displayed in the results is also the order if you populate your datagridview.

    2.)Try populating your dataGridview in design time, use SqlConneciton, SqlDataAdapter, and DataSet by drag and droping it to the form. Set the connection of your DataAdapter using SqlConnection object you created. Create a selectCommand and assign it into your DataAdapter and fill the dataset using the Adpater. Set the datasource of your grid to the created Dataset. Run your program.

    Hth,

    Michael Castillones

    Thursday, February 23, 2006 3:20 PM