数据库连接报错
实现将ECXEL导入到SQL中,但是执行报如下的错"链接服务器"NULL"的OLEDB访问接口microsoft.jet.oledb.4.0"的错,请问是什么问题,如何解决CommonDialog1.FileName = ""
CommonDialog1.Flags = 4096
CommonDialog1.Filter = "(*.xls)"
CommonDialog1.FilterIndex = 3
CommonDialog1.DialogTitle = "Open File(*.xls)"
CommonDialog1.Action = 1
If CommonDialog1.FileName = "" Then
MsgBox "no file selectd", 37, "checking"
Else
Dim Cn As ADODB.Connection
Dim strSQL As String
Dim lngRecsAff As Long
Set Cn = New ADODB.Connection
Cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=@5;Initial Catalog=AIS20100325101615;Data Source=DBSERVER"
strSQL = "INSERT INTO fcost22 select fyear,fperiod,fitemid,fnumber,fmateridprice FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=" & CommonDialog1.FileName & "',Sheet1$)"
Debug.Print strSQL
Cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
'executesql (strSQL)
Debug.Print "Records affected: " & lngRecsAff
MsgBox "本次共导入" & lngRecsAff & "条记录!"
Cn.Close
Set Cn = Nothing
[ 本帖最后由 sky_yang_sky 于 2010-3-26 15:40 编辑 ]