【问题标题】:How to upload excel files to database using linq?如何使用 linq 将 excel 文件上传到数据库?
【发布时间】:2010-05-17 04:30:00
【问题描述】:
  • 我的团队从事 asp.net 项目
  • 这里我们必须将 Excel 内容上传到数据库
  • 我们正在使用 linq
  • 请帮忙做同样的事情

【问题讨论】:

    标签: c# asp.net sql-server linq excel


    【解决方案1】:
    【解决方案2】:

    不使用 LINQ 的 2 种简单方法:

    using System.IO;
    using System.Data;
    using System.Data.OleDb;
    
    

    public DataRow[] GetUsers(string path, string id) { DataTable dt = new DataTable(); if (File.Exists(path)) { using (OleDbConnection con = new OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0", path))) { OleDbDataAdapter da = new OleDbDataAdapter(string.Format("select * from users", id), con); da.Fill(dt); } } string expression = String.Format("{0} = '{1}' and {2} <> ''", id, "first_name", "last_name"); string sort = "last_name ASC"; return dt.Select(expression, sort); }

    public DataTable GetUsers(string path, string id) { DataTable dt = new DataTable(); if (File.Exists(path)) { using (OleDbConnection con = new OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0", path))) { string expression = String.Format("{0} = '{1}' and {2} <> ''", id, "first_name", "last_name"); OleDbDataAdapter da = new OleDbDataAdapter(expression, con); da.Fill(dt); } } return dt; }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多