• 批量导入excel 狼


     原理:excel--就是个数据库--用sql语句将其读入到dataset中,然后再处理得得到的dataset,在保持到数据库中。

    /// <summary>
            /// 读取文件进行导入
            /// </summary>
            /// <param name="fileName">必须是全路径</param>
            private DataSet ImportToExcel(string fileName)
            {
                DataSet ds = new DataSet();
                try
                {
                    OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + fileName);
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }
                    else
                    {

                        TrainexamCommon.ExtMessageBox.Show("成绩导入错误提示:", "您选择的EXCEL文件正在被使用!请关闭后重试!", "OK", "ERROR");
                        return null;
                    }
                    OleDbCommand cmd = new OleDbCommand(@"select * from [Sheet1$]", con);
                    OleDbDataAdapter da = new OleDbDataAdapter();
                    da.SelectCommand = cmd;

                    da.Fill(ds);
                    con.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                return ds;
            }

  • 相关阅读:
    js debounce防抖技术
    我在项目中es6中数组的常用方法
    windows 部署Nginx转发http2.0协议
    AES加密,C#和java相同
    asp:Button js弹出提示框信息
    服务器不重启安装Asp.net Core 程序包
    C# string.Join的用法
    IIS部署asp.net core webapi
    ASP.net 加载不了字体Failed to load resource: the server responded with a status of 404 (Not Found)
    Windows Redis 取消保护模式C#进行访问
  • 原文地址:https://www.cnblogs.com/gowhy/p/2079792.html
Copyright © 2020-2023  润新知