导入.csv文件到gridview [英] Import .csv file to gridview

查看:101
本文介绍了导入.csv文件到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用开关盒导入".xls/.xlsx/.csv"文件,.xls/.xlsx"可以正常工作,但是".csv"文件向我显示如下错误

I am importing ".xls/.xlsx/.csv" file using switch case and ".xls/.xlsx" works fine but ".csv" file shows me the error as follows

"'*.csv' is not a valid path.  Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides." 


oconn.open()中.

有人可以帮帮我吗.

我正在使用以下代码:


in oconn.open().

Could someone please help me.

I''m using the following code:

switch (Extension)
        {
            case ".xls": //Excel 97-03
                conStr = String.Format(ConfigurationManager.ConnectionStrings["WorkingConnectionStringforxls"].ConnectionString + (char)34, path, (char)34);
                break;
            case ".xlsx": //Excel 07
                conStr = String.Format(ConfigurationManager.ConnectionStrings["WorkingConnectionStringforxlsx"].ConnectionString + (char)34, path, (char)34);
                break;
            case ".csv":  //CSV file
                conStr = String.Format(ConfigurationManager.ConnectionStrings["WorkingConnectionStringforcsv"].ConnectionString + (char)34, path, (char)34);
                break;
        }
        oconn = new OleDbConnection(conStr);
        oconn.Open();
        OleDbCommand ocmd1 = new OleDbCommand("select count(*) from [Sample input sheet$]", oconn);
        Int32 count = (Int32)ocmd1.ExecuteScalar();
        if (count == 0)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "errale", "alert('The excel sheet is empty');", true);
                }
        else
        {
            GridView1.DataSource = ExtractData();
            GridView1.DataBind();
            UpdateMaterial.Visible = true;
                    }
        oconn.Close();




这是我在web.config中使用的连接字符串:




This is the connection string I''m using in web.config:

<add name="WorkingConnectionStringforcsv" connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties={1}text;HDR=NO;FMT=Delimited;" />



预先感谢.



Thanks in advance.

推荐答案

",oconn); Int32 count =( Int32 )ocmd1.ExecuteScalar(); 如果(计数== 0 ) { ScriptManager.RegisterStartupScript( .GetType(), " " true ); } 其他 { GridView1.DataSource = ExtractData(); GridView1.DataBind(); UpdateMaterial.Visible = true ; } oconn.Close();
", oconn); Int32 count = (Int32)ocmd1.ExecuteScalar(); if (count == 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "errale", "alert('The excel sheet is empty');", true); } else { GridView1.DataSource = ExtractData(); GridView1.DataBind(); UpdateMaterial.Visible = true; } oconn.Close();




这是我在web.config中使用的连接字符串:




This is the connection string I''m using in web.config:

<add name="WorkingConnectionStringforcsv" connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties={1}text;HDR=NO;FMT=Delimited;" />



预先谢谢.



Thanks in advance.


能否请您告诉我们您的连接字符串是什么.
Can you please tell us that what is your connection string.
ConfigurationManager.ConnectionStrings["WorkingConnectionStringforcsv"]


可能存在问题


May be there is problem in that


检查这些博客
http://dotnetask.com/Resource.aspx?Resourceid=669 [ http://www.dotneter.com/import-data-from-csv-file- to-gridview [^ ]
--NDK
check these blogs
http://dotnetask.com/Resource.aspx?Resourceid=669[^]
http://www.dotneter.com/import-data-from-csv-file-to-gridview[^]
--NDK


这篇关于导入.csv文件到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆