怎样向表中添加数据?谢谢!!

yany71 2004-01-08 09:51:26
Dim str As String
Dim rs As New ADODB.Recordset
Dim curdb As Database
Dim action As Integer
.....
logname = Trim(Me.UserName)
pwd = Trim(Me.PassWord)
.....
str = "select * from users where 用户='" & logname & "' and 密码='" & pwd & "'"
Set rs = GetRS(str)
If rs.EOF Then
DoCmd.Beep
'若无此用户则插入
curdb.Execute "insert into users (用户,密码) values('" & logname & "','" & pwd & "')"
action = MsgBox("用户添加成功", vbOKOnly, "提示")
If action = 1 Then
DoCmd.Close acForm, "添加用户"
End If
end if


这是一段添加用户的程序片段,GetRS()是一个公共函数负责检索满足条件的记录。
若记录不存在则则将文本框中的内容添加在表中。可是运行时总提示“对象变量或
with块变量未设置" 我猜是curdb.Execute "insert into ...有问题,但不知
怎么该,请大家帮忙!谢谢!!
...全文
13 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧