BIND TO DATAGRIDVIEW

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C# 
C#
 865  View(s)
Ratings:
Rate this:

How can i bind data to datagridview?

DataTable table = new DataTable();

string pot = "Provider=Microsoft.Ace.OLEDB.12.0; Data Source = " + textbox_path.Text + ";Extended Properties=\"Excel 8.0; HDR=Yes;\";";

OleDbConnection pove = new OleDbConnection(pot);

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * from [" + textbox_sheet.Text + "$]", pove);

DataTable dt = new DataTable();

myDataAdapter.Fill(dt); /* napaka | oldedb driver ? :O*/

dataGridView1.DataSource = dt;

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Bind to datagridview

    Hi Ankit,


    Add dataGridView1.DataBind(); after dataGridView1.DataSource = dt;.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!