使用c#.net在oracle数据库中使用oracle.managed.dataaccess.client插入excel批量数据 [英] Insert excel bulk data in oracle database using oracle.managed.dataaccess.client using c#.net

查看:172
本文介绍了使用c#.net在oracle数据库中使用oracle.managed.dataaccess.client插入excel批量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要使用C#.net



使用Oracle.Managed.DataAccess.Client将包含n条记录的excel文件(datatable / dataset)上传到oracle数据库中我尝试过:



看起来托管数据访问不支持批量数据插入。但不确定是否可能有一些想法

Need to upload the excel file(datatable/dataset) contains n number of records into oracle database using Oracle.Managed.DataAccess.Client using C#.net

What I have tried:

It looks like Managed data access doesn't support Bulk data insert. But not sure whether there may be some ideas

推荐答案

使用此

Use this
protected void btnUpload_Click(object sender, EventArgs e)  
{  
 try  
 {  
    if (fUpload.HasFile)  
     {  
        string Path = Server.MapPath(fUpload.FileName);  
        FillDatasetExcel(Path);  
     }  
 }  
 catch (Exception ex)  
 {  
   throw ex;  
 }  
}  
public DataTable FillDatasetExcel(string filepath)  
{  
  string path = filepath;  
  // Prepare cnnection string  
  string connectionstring =  
 @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0 Xml;HDR=YES;FMT=Delimited';";  
 byte[] Bytes = fUpload.FileBytes;  
  File.WriteAllBytes(path, Bytes);  
  OleDbConnection connection = new OleDbConnection();  
  connection.ConnectionString = connectionstring;  
  OleDbCommand command = new OleDbCommand();  
  command.CommandType = CommandType.Text;  
  command.Connection = connection;  
  command.CommandText = "Select * FROM [Sheet1


;
connection.Open();
// 创建数据表对象
DataTable dt = new DataTable();
// 执行Reader并将数据加载到datatable
dt.Load( Command.ExecuteReader却());
// 关闭连接
connection.Close();
return dt;
}
}
"; connection.Open(); // create data table object DataTable dt = new DataTable(); // Execute Reader and load the data into datatable dt.Load(command.ExecuteReader()); // Close the connection connection.Close(); return dt; } }


这篇关于使用c#.net在oracle数据库中使用oracle.managed.dataaccess.client插入excel批量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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