private void Form1_Load(object sender, System.EventArgs e)
{
// Connection string for ODBC Excel Driver
string ConnectionString =
@"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\Employees.xls";
OdbcConnection conn = new OdbcConnection(ConnectionString);
// Table in Excel can be thought of as sheets and are queried as shown
string sql = "Select EmployeeID, FirstName, LastName FROM Employees";
conn.Open();
OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
dataGrid1.DataSource = ds.DefaultViewManager;
listBox1.DataSource = ds.DefaultViewManager;
listBox1.DisplayMember = "Employees.FirstName";
}
Sunday, February 20, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment