none
Get field names of a table in Access RRS feed

  • Question

  • Hi

    I am new to C#.net and Access database. I am trying to create an application that can read a table and display its column names in a datagrid along with check boxes beside each data.

    All my efforts using Schema / MSysObjects etc have so far failed (I gleaned these info's from net). The MSysObjects approach failed because, I am not able to figure out how to give read permission in ACCESS - 2007.

    Can anyone help me to get the fields names of a particular table(in MS-ACCESS) and display only those in a data grid.

    Thanks




    Wednesday, October 3, 2007 9:53 PM

Answers


  • //This restriction is used to restrict the details to a particular table - instead of "tableName" give your table name
                string[] restrictions1 = new string[4] {null , null, tableName, null };
               
                //Open your connection
                conn1.Open();

                //Get the schema details
                DataTable tt = conn1.GetSchema("Columns",restrictions1);

                ArrayList col_Names = new ArrayList();

                //The third column gives the column names and so populate it into an arraylist and use it
                for (int j = 0; j < tt.Rows.Count; j++)
                {
                    string column = tt.Rows[j][3].ToString();
                    col_Names.Add(column);
                }


    Tuesday, October 9, 2007 3:11 PM

All replies



  • I have found the answer. Please dont bother replying.

    thanks
    Friday, October 5, 2007 5:43 PM
  • Have you tried to use GetOleDbSchemaTable method of OleDbConnection class? It returns information about objects in a database

    Saturday, October 6, 2007 12:49 PM
    Moderator
  •  

    Hi

     

     

    if you found the answer Plz posted it becasue am also have same probs.

     

    Thanks n Advance

     

    Senselva

     

    Tuesday, October 9, 2007 5:30 AM
  • Have you tried my suggestion using method of OledConnection class?

    Tuesday, October 9, 2007 10:36 AM
    Moderator
  • vindastra

     

    Could you please share what you have found with everyone?

    Tuesday, October 9, 2007 10:37 AM
    Moderator

  • //This restriction is used to restrict the details to a particular table - instead of "tableName" give your table name
                string[] restrictions1 = new string[4] {null , null, tableName, null };
               
                //Open your connection
                conn1.Open();

                //Get the schema details
                DataTable tt = conn1.GetSchema("Columns",restrictions1);

                ArrayList col_Names = new ArrayList();

                //The third column gives the column names and so populate it into an arraylist and use it
                for (int j = 0; j < tt.Rows.Count; j++)
                {
                    string column = tt.Rows[j][3].ToString();
                    col_Names.Add(column);
                }


    Tuesday, October 9, 2007 3:11 PM
  • Thanks a Lot, it solved my error.
    Wednesday, June 1, 2011 6:07 AM