各位大侠帮帮看看,我这几句话怎么不能添加数据到数据库阿
谢谢!!!!!!!!!!!!!!!!!Public DbCon As ADODB.Connection '声明一个用于连接数据库的对象
'检查文件是否存在
Public Function FileExist(FileName As String) As Boolean
FileExist = Dir(FileName) <> ""
End Function
'######################打开数据库
Public Sub MakeConnection(DbRec As ADODB.Recordset, dataname As String) 'DbRec创建一个记录集,dataname表的名称
Dim PartRect As String
apppath = "C:\Program Files\
AutoCAD 2004\TDCAM"
Set DbCon = New ADODB.Connection '将Connection对象实例化
Set DbRec = New ADODB.Recordset
DbCon.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & apppath & "\database.MDB;"
DbCon.Open
Set DbRec.ActiveConnection = DbCon
DbRec.Open "PartRect", DbCon, adOpenKeyset, adLockPessimistic '"select * from part", DbCon
End Sub
'##########################关闭数据库
Public Sub CloseDataBase(DbRec As ADODB.Recordset)
DbRec.Close
Set DbRec = Nothing
DbCon.Close
Set DbCon = Nothing
End Sub
Dim PartCir As String
Dim CirDbRec As ADODB.Recordset
Set CirDbRec = New ADODB.Recordset
Set DbCon = New ADODB.Connection
If DbCon.State <> adStateClosed Then '判断连接是否关闭
DbCon.Close
End If
Call MakeConnection(CirDbRec, PartCir)
With CirDbRec
If CirDbRec.State <> adStateClosed Then '判断记录集是否关闭
CirDbRec.Close
End If
.ActiveConnection = DbCon
.Open "PartCir ", DbCon, adOpenKeyset, adLockBatchOptimistic
Do Until CirDbRec.EOF
.MoveNext
Loop
.AddNew
.Fields("零件号") = Name
.Fields("r") = l1
.Update
End With
Call CloseDataBase(CirDbRec)