Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Getting Column Names Through Query

Getting Column Names Through Query

Scheduled Pinned Locked Moved Database
csharpdatabase
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sindhutiwari
    wrote on last edited by
    #1

    HI My Aim is to get the column names of a access database table and store it to a combobox using C#.net if any one knows the query or any clue please let me know regards sindhu tiwari

    INNOVATIVE

    M P M 3 Replies Last reply
    0
    • S sindhutiwari

      HI My Aim is to get the column names of a access database table and store it to a combobox using C#.net if any one knows the query or any clue please let me know regards sindhu tiwari

      INNOVATIVE

      M Offline
      M Offline
      Muhammad Shahid Farooq
      wrote on last edited by
      #2

      string connectionString; OleDbConnection connection = new OleDbConnection(); OleDbDataAdapter dataAdapter; DataSet dataSet = new DataSet(); public Form1() { InitializeComponent(); } public void openConnection() { try { connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Test.mdb"; connection.ConnectionString = connectionString; connection.Open(); } catch (Exception e) { MessageBox.Show(e.ToString()); } } public void closeConnection() { try { if (connection.State != 0) { connection.Close(); } } catch (Exception e) { MessageBox.Show(e.ToString()); } } public void fillDataset(string query, DataSet dataSet) { openConnection(); dataAdapter = new OleDbDataAdapter(query, connection); dataAdapter.Fill(dataSet, "ColumnNames"); closeConnection(); } public void fillComboBox() { string strQuery = "Select * From Table1"; fillDataset(strQuery, dataSet); foreach (DataColumn dataColumn in dataSet.Tables[0].Columns) { cmbColumnNames.Items.Add(dataColumn.ColumnName); } } private void Form1_Load(object sender, EventArgs e) { fillComboBox(); }

      1 Reply Last reply
      0
      • S sindhutiwari

        HI My Aim is to get the column names of a access database table and store it to a combobox using C#.net if any one knows the query or any clue please let me know regards sindhu tiwari

        INNOVATIVE

        P Offline
        P Offline
        pmarfleet
        wrote on last edited by
        #3

        Why have you posted this question? The link I sent you in response to your previous question also explained how to get a list of fields for an Access table. You should learn to search Google for answers to your questions before posting. Otherwise it looks like you can't be bothered to search for a solution to your problem yourself.

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        1 Reply Last reply
        0
        • S sindhutiwari

          HI My Aim is to get the column names of a access database table and store it to a combobox using C#.net if any one knows the query or any clue please let me know regards sindhu tiwari

          INNOVATIVE

          M Offline
          M Offline
          Mitesh Darji
          wrote on last edited by
          #4

          :cool: you can use the following query in your code ... SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'name_of_the_table'

          Mitesh Darji

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups