开发者

Failed to create file - excel to gridview

I have the next code:

   <asp:gridview id="GridView1" runat="server" cellpadding="6" gridlines="None" 
    bordercolor="#开发者_StackOverflow336699" borderstyle="Solid" borderwidth="1px">

    <headerstyle backcolor="#336699" font-bold="True" forecolor="White" />
    </asp:gridview>

And code behind:

    protected void Page_Load(object sender, EventArgs e)
{
    string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|App_Data|Machreta.xls;Extended Properties='Excel 8.0;HDR=Yes;'";

    string query = "SELECT * FROM [Sheet1$]";

    DataSet excelDataSet = new DataSet();
    OleDbDataAdapter da = new OleDbDataAdapter(query, strConn);

    da.Fill(excelDataSet);

    GridView1.DataSource = excelDataSet;
    GridView1.DataBind();

}

I'm get the error:

Failed to create file

To the line:

    da.Fill(excelDataSet);

why?


Try using:

string strConn = 
    @"Provider=Microsoft.Jet.OLEDB.4.0;" +
    @"Data Source=|DataDirectory|\Machreta.xls;" +
    @"Extended Properties='Excel 8.0;HDR=Yes;'";

or

string strConn = 
    @"Provider=Microsoft.Jet.OLEDB.4.0;" +
    @"Data Source=|App_Data|\Machreta.xls;" +
    @"Extended Properties='Excel 8.0;HDR=Yes;'";

I splitted strings over many rows just for easy reading.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜