dataset读取excel中的数据到打dataset中

string strFileName = FileUpload1.FileName;
        string imgpath = Server.MapPath("~/inputFile/");
        FileUpload1.SaveAs(imgpath + strFileName);
        try
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + imgpath + "\\" + strFileName + ";" + "Extended Properties=Excel 8.0;";
            OleDbConnection conn = new OleDbConnection(strConn);
            OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", strConn);oda.Fill(ds);
            oda.Update(ds);
            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();
            
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

你可能感兴趣的:(dataset读取excel中的数据到打dataset中)