vb执行调用以下程序时报错: Dim cn As New ADODB.Connection
Dim strtemp As String
Dim cmd As New ADODB.Command
Dim rs1 As New ADODB.Recordset
cn.Open ("Provider=sqloledb.1;data source=erp1;initial catalog=AIS20090408172013;user id=sa;password=hq1234")
cmd.ActiveConnection = cn On Error GoTo ErrHandle
cmd.CommandText = "select * into tempbom from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 8.0;HDR=YES;DATABASE=" & Label1.Caption & "',sheet1$)"
cmd.CommandType = adCmdText
cmd.Execute
MsgBox "执行数据插入完成!" 'vbmsgboxstyle.vbokonly
cn.Close
ErrHandle:
' cn.RollbackTrans
MsgBox Err.Description
错误:OLDB错误跟踪[OLE/DB Provider 'MICROSOFT.JET.oledb.4.0',IDBInitialize::initializw returned 0x80004005: 提供程序未给出有关错误信息
请各位能人帮忙解决下!
Dim strtemp As String
Dim cmd As New ADODB.Command
Dim rs1 As New ADODB.Recordset
cn.Open ("Provider=sqloledb.1;data source=erp1;initial catalog=AIS20090408172013;user id=sa;password=hq1234")
cmd.ActiveConnection = cn On Error GoTo ErrHandle
cmd.CommandText = "select * into tempbom from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 8.0;HDR=YES;DATABASE=" & Label1.Caption & "',sheet1$)"
cmd.CommandType = adCmdText
cmd.Execute
MsgBox "执行数据插入完成!" 'vbmsgboxstyle.vbokonly
cn.Close
ErrHandle:
' cn.RollbackTrans
MsgBox Err.Description
错误:OLDB错误跟踪[OLE/DB Provider 'MICROSOFT.JET.oledb.4.0',IDBInitialize::initializw returned 0x80004005: 提供程序未给出有关错误信息
请各位能人帮忙解决下!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'函数功能:连接指定的数据库
'参数说明:cnnP:数据库连接对象;
' :adoP:数据集存储对象;
' :strPath:数据库路径;
' :strPassword:数据库密码;
'返回说明:True:连接成功 False:连接失败
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function funConnectDataBase(cnnP As ADODB.Connection, adoP As ADODB.Recordset, ByVal strPath As _
String, ByVal strPassword As String) As Boolean
On Error GoTo errFunction
Set cnnP = New ADODB.Connection
Set adoP = New ADODB.Recordset
cnnP.Provider = "Microsoft.Jet.OLEDB.4.0"
cnnP.Open "Data Source = " & strPath & ";jet oledb:database password=" & strPassword
funConnectDataBase = True
Exit Function
errFunction:
funConnectDataBase = False
End Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'函数功能:关闭数据库连接对象和数据文件的关联
'参数说明:cnnP:数据库连接对象;
' :adoP:数据库存储对象;
'返回说明:True:关闭连接成功 False:关闭连接失败
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function funCloseDataBase(cnnP As ADODB.Connection, adoP As ADODB.Recordset) As Boolean
On Error GoTo errFunction
Set adoP = Nothing
Set cnnP = Nothing
funCloseDataBase = True
Exit Function
errFunction:
funCloseDataBase = False
End Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'过程功能:对指定的对象执行指定的SQL语句
'参数说明:cnnP:ADO连接对象
' :adoP:ADO记录集对象
' :strSql:SQL语句
' :bolQueryRecord:是否是查询记录集
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Public Sub subExcuteSQL(cnnP As ADODB.Connection, adoP As ADODB.Recordset, strSql As String, bolQueryRecord _
As Boolean)
If bolQueryRecord Then '如果是查询记录集
adoP.Open strSql, cnnP, adOpenStatic, adLockBatchOptimistic
Else
cnnP.Execute strSql
End If
End Sub