6

场景:我正在开发一个 Web 应用程序,它允许用户将 Excel 文件上传到 SQL Server 2008 R2 数据库中各自的表中。当用户单击上传按钮时,我还在运行使用 SSIS 开发的 ETL 流程。

我的开发环境:Asp.net、IIS7、C#、SQL Server 2008 R2

我目前面临将文件的文件名保存到表格中的另一列的问题,因为我还将为用户创建 gridview 功能,以查看已经上传到数据库中的文件并使用户能够下载错误文件。

问题:在 ETL 过程中运行 SSIS 包时,有什么方法可以将文件名保存到相同的表中?

以下是我的代码示例:

string filePath1 = Server.MapPath(System.IO.Path.GetFileName(file.FileName.ToString()));
file.SaveAs(filePath1);

package = app.LoadPackage(packageString, null);
package.Connections["Excel Connection Manager"].ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath1 + ";Extended Properties=Excel 12.0;HDR=YES;IMEX=1";
Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();

此方法允许我检索 fileName :

String.Format("File : {0} uploaded.", file.FileName)

那么当我执行包时,如何同时将文件名保存到表中呢?

4

1 回答 1

0
  string connectionString = DAO.GetConnectionString(); 
SqlConnection sqlConn = new SqlConnection(connectionString);
 sqlConn.Open() 
strQuery = "update uploadSummaryDB set fileName = @fileName where id in (select max(id) from uploadSummaryDB)"; 
SqlCommand command = new SqlCommand(strQuery,sqlConn); 
command.Parameters.Add("@fileName", SqlDbType.NVarChar).Value = file.FileName.ToString(); command.ExecuteNonQuery();
于 2013-03-28T14:44:51.733 回答