Net-informations.com
SiteMap  | About    

How to find Column Definition OLEDB

Dataset Object represents a collection of data retrieved from the Data Source. The OleDbDataAdapter object allows us to populate DataTable in a DataSet. We can use Fill method in the OleDbDataAdapter Object for populating data in a Dataset. The Dataset can contain more than one Table at a time. The data set may comprise data for one or more members, corresponding to the number of rows.

The data inside Table is in the form of Rows and Columns . The DataRow class represents the actual data contained in a table. You use the DataRow and its properties and methods to retrieve, evaluate, and manipulate the data in a table. In some situations we have to find the column headers in a DataTable. There is a ColumnsCollection Object in the Datatable hold the column Definitions. The following C# Source Code shows how to find Column Definitions from a Datatable.




using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connetionString = null;
            OleDbConnection connection ;
            OleDbDataAdapter oledbAdapter ;
            DataSet ds = new DataSet();
            DataTable dt ;
            string sql = null;
            int i = 0;

            connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;";
            sql = "Your SQL Statement Here";

            connection = new OleDbConnection(connetionString);
            try
            {
                connection.Open();
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbAdapter.Fill(ds, "OLEDB Temp Table");
                oledbAdapter.Dispose();
                connection.Close();

                dt = ds.Tables[0];
                for (i = 0; i <= dt.Columns.Count - 1; i++)
                {
                    MessageBox.Show (dt.Columns[i].ColumnName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not open connection ! ");
            } 

        }
    }
}






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.