Dim ConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sample1.xls;Extended Properties=Excel 8.0"
Dim Conn As Connection = New Connection(ConString)
Conn.Open()
Dim Cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]", Conn)
Dim dtAdapter As OleDbDataAdapter = New OleDbDataAdapter()
dtAdapter.SelectCommand = Cmd
Dim ds As DataSet = New DataSet()
dtAdapter.Fill(ds, "Employees")
GridView1.DataSource = ds.Tables(0).DefaultView
GridView1.DataBind()
Conn.Close()
Code (C#)
string ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sample1.xls;Extended Properties=Excel 8.0";
Connection Conn = new Connection(ConString);
Conn.Open();
OleDbCommand Cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", Conn);
OleDbDataAdapter dtAdapter = new OleDbDataAdapter();
dtAdapter.SelectCommand = Cmd;
DataSet ds = new DataSet();
dtAdapter.Fill(ds, "Employees");
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
Conn.Close();