Thursday, 20 December 2012

Get the field names of a MS access database table

Solutions : 
using System.Data.OleDb;  //namespace


OledbConnString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="C:\\dbBCR.mdb";
            OleDbConnection Conn = new OleDbConnection(OledbConnString);
            Conn.Open();
            OleDbCommand Command = new OleDbCommand("select * from Table1", Conn);
            OleDbDataReader reader = Command.ExecuteReader();
            DataTable schemaTable = reader.GetSchemaTable();
                        foreach (DataRow row in schemaTable.Rows)
            {
                  MessageBox.Show(row.Field<string>("ColumnName"));
             }
            Conn.Close();

No comments:

Post a Comment