protected void Button1_Click(object sender, EventArgs e)
{
string xConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("ExcelImport.xls") + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection objXConn = new OleDbConnection(xConnStr);
string sql = "SELECT * FROM [Salary$]";
OleDbCommand cmd = objXConn.CreateCommand();
cmd.CommandText = sql;
OleDbDataAdapter adpt = new OleDbDataAdapter();
adpt.SelectCommand = cmd;
DataSet ds = new DataSet();
adpt.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
No comments:
Post a Comment