ADO数据库添加数据一个正常一个出现,不知道那里的问题?

QQ342151559 2008-03-13 03:31:28
ADOConnetion.bas
Option Explicit
'定义公用数据库
'************************************
Public BookConn As ADODB.Connection
Public BookRs As ADODB.Recordset
Public BookRsStr As String '定义查询语句 BookInformation
Public BookRsStr1 As String '定义查询语句 Summary
Public BookRsStr2 As String '定义查询语句 Type & Language & Creative
Public BookRsStr3 As String
Public BookRsStr4 As String
Public BookRsCount As Integer '定义查询语句 BookRs.Count

'************************************
'定义数据库连接
Public Function BookADOConn(ByVal txtSQL As String) As ADODB.Recordset
Dim BookConnStr As String

BookConnStr = App.Path & "\Book.mdb"
Set BookConn = New ADODB.Connection
BookConn.Open "provider=microsoft.jet.OLEDB.4.0;Data source= " & BookConnStr
Set BookRs = New ADODB.Recordset
BookRs.Open txtSQL, BookConn, adOpenKeyset, adLockPessimistic
Set BookADOConn = BookRs
End Function

'撤销数据库资源
Public Function CancelADOConn()
Set BookRs = Nothing
Set BookConn = Nothing
End Function


frmType.frm

Option Explicit

Private Sub cmdAdd_Click()
BookRsStr2 = "select * from Type where Type='" & Trim(txtType.Text) & "'"
Set BookRs = BookADOConn(BookRsStr2)
If BookRs.EOF = False Then
MsgBox "Error,Please Input", vbOKOnly + vbExclamation, "警告"
BookRs.Close
txtType.SetFocus
Else

BookRsStr2 = "select * from Type"
Set BookRs = BookADOConn(BookRsStr2)
With BookRs
.AddNew
.Fields(1) = txtType.Text
.Update
.Close
End With
CancelADOConn

End If
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub Combo1_GotFocus()
Combo1.Clear
BookRsStr2 = "select * from Type"

'Type
Set BookRs = BookADOConn(BookRsStr2)
For BookRsCount = 1 To BookRs.RecordCount
Combo1.AddItem BookRs.Fields(1)
BookRs.MoveNext
Next BookRsCount
BookRs.Close
CancelADOConn
End Sub

frmLanguage.frm

Option Explicit

Private Sub cmdAdd_Click()
BookRsStr3 = "select * from Language where Language='" & txtLanguage.Text & "'"
Set BookRs = BookADOConn(BookRsStr3)
If BookRs.EOF = False Then
MsgBox "Error,Please Input", vbOKOnly + vbExclamation, "警告"
BookRs.Close
txtLanguage.SetFocus
Else

BookRsStr3 = "select * from Language"
Set BookRs = BookADOConn(BookRsStr3)
With BookRs
.AddNew
.Fields(1) = txtLanguage.Text
.Update
.Close
End With
CancelADOConn

End If
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub Combo1_GotFocus()
Combo1.Clear
BookRsStr3 = "select * from Language"

'Type
Set BookRs = BookADOConn(BookRsStr3)
For BookRsCount = 1 To BookRs.RecordCount
Combo1.AddItem BookRs.Fields(1)
BookRs.MoveNext
Next BookRsCount
BookRs.Close
CancelADOConn
End Sub

其中添加Type的没有出现错误,但是添加Language的出现 Open Recordset错误

哪位,前辈帮忙看看


...全文
26 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
QQ342151559 2008-03-14
可能是因为关键字的原因吧.我重新写了(换了表明和字段)没有问题了
谢谢
回复
vbman2003 2008-03-13
select * from Language where Language='" & txtLanguage.Text & "
表名、字段名称用数据库关健字,表名和字段同名,我认为都是不规范的写法
回复
vbman2003 2008-03-13
你的表名有用了数据库关健字的嫌疑(偶不能确定),sql语句中用[]号将表名括起来试试:

select * from [Type]
select * from [Language]
回复
QQ342151559 2008-03-13
没有啊..
表Type和Language都在Book.mdb中且字段也没有问题...
回复
of123 2008-03-13
Language 表是否存在,有无拼写错误?其中,Language 字段是否存在,有无拼写错误?
回复
相关推荐
基于java的企业人事管理系统设计--软件工程课程设计(含源码与论文设计).rar 1 引言 4 1.1 课程设计目标 4 1.2 编程工具(编程环境)介绍 4 1.3 实施时间及主要实施步骤 4 2 需求分析 5 3 系统总体设计 6 4 数据设计 6 5 主要功能模块的设计与实现 10 5.1 功能模块1详细设计(综合查询员工信息)..........................................................10 5.1.1 详细设计.......................................................................................................10 5.1.2 算法流程........................................................................................................15 5.1.3 界面设计及测试结果.....................................................................................15 6 调试分析 15 7 用户手册 16 8 测试结果 17 8.1 员工信息的添加...................................................................................................17 8.2 员工信息的修改...................................................................................................17 8.3 员工信息的删除...................................................................................................18 8.4 员工信息的综合查询...........................................................................................18 8.5 员工信息按性别统计的结果................................................................................19 8.6 员工信息按状态统计的结果...............................................................................19 8.7 员工信息按职称统计的结果................................................................................20 9 结论 20 10 参考文献 20
发帖
VB基础类
创建于2007-09-28

7492

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-03-13 03:31
社区公告
暂无公告