with adodc.recordset
.addnew
.update
end with
可是对于addnew 系统提示说需要对象 对于update 系统提示说字段名不能为空
到底是怎么回事
还有就是 我在运行的时候 添加不好似添加而几乎成了替换 修改的时候不能在本次运行的结果中显示出来 只能在第二次运行的时候显示结果
虚心垂询 望得答复 谢谢
[此贴子已经被作者于2006-7-4 17:38:29编辑过]
以下是我之前帮一位朋友修改的代码...在这里转发你看看..
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'模 块 功 能 : 使 用 ADO 对 象 添 加 数 据
'最 后 修 改 时 间 : 6 月 6 日
'修 改 员 : 梁 嘉 辉 (if)
'E - Mail : myfend_liang@yahoo.com.cn
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim g_Connect As ADODB.Connection
Dim g_Recordset As ADODB.Recordset
Private Sub Form_Load()
Set g_Connect = CreateObject("ADODB.Connection")
Dim strConnection As String
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\书刊类别库1.mdb"
g_Connect.Open strConnection
End Sub
Private Sub Command1_Click()
Dim sql As String
If Trim(Text1.Text) = "" Then
MsgBox "类别编号为空", vbokoly + vbExclamation, ""
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "类别名称为空", vbokoly + vbExclamation, ""
Text2.SetFocus
Exit Sub
End If
Set g_Recordset = CreateObject("ADODB.Recordset")
sql = "SELECT * FROM 书刊类别 WHERE 类别编号 ='" & Text1.Text & "'"
g_Recordset.Open sql, g_Connect, adOpenKeyset, adLockPessimistic
If g_Recordset.EOF Then
g_Recordset.AddNew
g_Recordset.Fields("类别编号") = Trim(Text1.Text)
g_Recordset.Fields("类别名称") = Trim(Text2.Text)
g_Recordset.Update
MsgBox "添加成功", vbOKOnly, ""
g_Recordset.Close
Else
MsgBox "类别编号号重复", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Text1.Text = ""
g_Recordset.Close
Exit Sub
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set g_Connect = Nothing
Set g_Recordset = Nothing
End Sub