[求助]小女求助
<h4>小女求助</h4><div class="tpc_content"><b>各位大侠帮帮看看,我这几句话怎么不能添加数据到数据库阿<br/> 谢谢!!!!!!!!!!!!!!!!!</b><br/>Public DbCon As ADODB.Connection '声明一个用于连接数据库的对象<br/><br/>'检查文件是否存在<br/>Public Function FileExist(FileName As String) As Boolean<br/>FileExist = Dir(FileName) <> ""<br/>End Function<br/><br/>'######################打开数据库<br/>Public Sub MakeConnection(DbRec As ADODB.Recordset, dataname As String) 'DbRec创建一个记录集,dataname表的名称<br/>Dim PartRect As String<br/> apppath = "C:\Program Files\AutoCAD 2004\TDCAM"<br/> Set DbCon = New ADODB.Connection '将Connection对象实例化<br/> Set DbRec = New ADODB.Recordset<br/> DbCon.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & apppath & "\database.MDB;"<br/> DbCon.Open<br/> Set DbRec.ActiveConnection = DbCon<br/> DbRec.Open "PartRect", DbCon, adOpenKeyset, adLockPessimistic '"select * from part", DbCon<br/>End Sub<br/><br/>'##########################关闭数据库<br/>Public Sub CloseDataBase(DbRec As ADODB.Recordset)<br/>DbRec.Close<br/>Set DbRec = Nothing<br/>DbCon.Close<br/>Set DbCon = Nothing<br/>End Sub<br/><br/><br/>Dim PartCir As String<br/>Dim CirDbRec As ADODB.Recordset<br/>Set CirDbRec = New ADODB.Recordset<br/>Set DbCon = New ADODB.Connection<br/>If DbCon.State <> adStateClosed Then '判断连接是否关闭<br/> DbCon.Close<br/>End If<br/>Call MakeConnection(CirDbRec, PartCir)<br/>With CirDbRec<br/> If CirDbRec.State <> adStateClosed Then '判断记录集是否关闭<br/> CirDbRec.Close<br/> End If<br/> .ActiveConnection = DbCon<br/> .Open "PartCir ", DbCon, adOpenKeyset, adLockBatchOptimistic<br/> Do Until CirDbRec.EOF<br/> .MoveNext<br/> Loop<br/> .AddNew<br/> .Fields("零件号") = Name<br/> .Fields("r") = l1<br/> .Update<br/>End With<br/>Call CloseDataBase(CirDbRec)</div> <p>程序可能不全,好像语句还有错误,如果是手敲出来的难免出错,无法通过编译,可能要引用"microsoft ActiveX Data Object 2.5 Library",引用与autocad和office版本有直接关系,程序好像要放到模块里才行。把程序的全段都copy出来行吗?可以试着参考“二次开发”教程修改一下,可能就通过了。</p>
页:
[1]