yusicad 发表于 2007-7-28 12:46:00

ADDNEW方法向ACCESS添加记录的问题

<p>Private Sub UserForm_Initialize()<br/>'创建ADO连接并打开<br/>Set cn = New ADODB.Connection<br/>cn.CursorLocation = adUseClient<br/>cn.Provider = "Microsoft.Jet.oledb.4.0;"<br/>ConStr = "Data Source=C:\Documents and Settings\Administrator\桌面\元数据程序\元数据.mdb;"<br/>cn.Open ConStr</p><p>Set adoRs = New Recordset<br/>adoRs.Open "DLGMetaDataBysheet", cn, adOpenKeyset, adLockBatchOptimistic<br/>If adoRs.RecordCount &gt; 0 Then<br/>adoRs.MoveLast<br/>adoRs.MoveFirst<br/>End If<br/>End Sub</p><p>Private Sub cmdOk_Click()<br/>Dim control As control<br/>On Error GoTo errHandle<br/>With adoRs<br/>.AddNew<br/>&nbsp;.Fields(0) = CInt(txtId.Text)<br/>&nbsp;.Fields(1) = CInt(txtNum.Text)<br/>&nbsp;.Fields(2) = txtName.Text<br/>&nbsp;.Fields(3) = txtHao.Text<br/>&nbsp;.Fields(4) = txtMapName.Text</p><p>.Update<br/>&nbsp;End With</p><p>Exit Sub</p><p>End Sub</p><p>Private Sub UserForm_Terminate()<br/>&nbsp;adoRs.Close<br/>&nbsp;cn.Close<br/>End Sub</p><p>我现在程序运行时可以看到以添加成功,可是为什么数据库里没有记录呢?请高手指教</p>

yusicad 发表于 2007-7-28 15:49:00

<p>哈哈我已经解决了是我把打开数据表的参数选错了</p>
页: [1]
查看完整版本: ADDNEW方法向ACCESS添加记录的问题