我有一个 SSIS 包,用于将 Excel 文件中的数据上传到 Sql Server 2005 表中。
Excel 文件将包含 20k - 30k 行范围内的不同行数据。
当所有数据正确时,上传工作正常。但当即使在单行中出现小问题时,显然也会失败。例如强制值呈现 null、不可转换值(数据类型不匹配)等。
我想在上传之前验证Excel文件,并想告诉用户哪一行和哪一列出现错误...
关于如何实现这一目标而不消耗太多时间和资源的任何想法。
Thanks
最简单的方法可能是加载到没有任何强制值等的临时表中,并在将其附加到主表之前进行检查。
编辑重新评论
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
''This is not necessarily the best way to get the workbook name
''that you need
strFile = Workbooks(1).FullName
''Note that if HDR=No, F1,F2 etc are used for column names,
''if HDR=Yes, the names in the first row of the range
''can be used.
''This is the Jet 4 connection string, you can get more
''here : http://www.connectionstrings.com/excel
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
''Note that HDR=Yes
''Pick one:
strSQL = "SELECT Frst, Secnd FROM TheRange WHERE SomeField Is Null" ''Named range
strSQL = "SELECT Frst, Secnd FROM [Sheet1$C3:C67] WHERE Val(Secnd)=0" ''Range
strSQL = "SELECT Frst, Secnd FROM [Sheet1$] WHERE First<Date()" ''Sheet
rs.Open strSQL, cn
Sheets("Sheet2").Cells(2, 1).CopyFromRecordset rs
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)