接着急问!!!刚才帮忙的朋友!再看!

bluesanke 2003-04-03 03:05:40
Option Explicit
Dim Mycn As New ADODB.Connection '数据库连接对象,用于打开数据库
Dim Myrs1 As New ADODB.Recordset '记录集对象,用于存入记录的
Dim Myrs2 As New ADODB.Recordset '记录集对象,用于存入记录的
Private Sub Command1_Click()
Dim cnstring As String '用于存放连接字符串的
cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd"
Mycn.Open cnstring
Mycn.CursorLocation = adUseClient
If Option1.Value = True Then
If Text1.Text = "" Then
MsgBox "请正确填写申请书编号!", vbOKOnly + vbExclamation, "信息提示"
Text1.SetFocus
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
MSHFlexGrid1.Text = Myrs1.Fields("DCT_BH") & ""

MsgBox "不存在这个进库单号码", vbOKOnly + vbExclamation, "信息提示"
Text1 = ""
Text1.SetFocus
End If
Exit Sub
End If
这是我现在正用的代码,可是只能查一遍,第2次就说实施错误,‘3705’对象打开时操作不被允许!

...全文
5 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
chenyu5188 2003-04-03
呵呵,我又来也。
你的出错我知道哪儿错了。
Option Explicit
Dim Mycn As New ADODB.Connection '数据库连接对象,用于打开数据库
Dim Myrs1 As New ADODB.Recordset '记录集对象,用于存入记录的
Dim Myrs2 As New ADODB.Recordset '记录集对象,用于存入记录的
Private Sub Command1_Click()
Dim cnstring As String '用于存放连接字符串的
cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd"
Mycn.Open cnstring
Mycn.CursorLocation = adUseClient
If Option1.Value = True Then
If Text1.Text = "" Then
MsgBox "请正确填写申请书编号!", vbOKOnly + vbExclamation, "信息提示"
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
If Myrs1.BOF And Myrs1.EOF Then
MsgBox "不存在申请书编号!!!", vbOKOnly + vbExclamation, "信息提示"

Text1 = ""
Text1.SetFocus
Myrs1.Close
Set Myrs1 = Nothing
Mycn.Close
Set Mycn=nothing
Exit Sub
End If
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
MSHFlexGrid1.Text = Myrs1.Fields("DCT_BH") & ""
MSHFlexGrid1.Col = 1
.....................
Myrs1.Close
Set Myrs1 = Nothing
Else
Myrs1.Close
Set Myrs1 = Nothing
Exit Sub
End If
End If
If Option2.Value = True Then
If Text2.Text = "" Then
MsgBox "请正确填写土地使用者!", vbOKOnly + vbExclamation, "信息提示"
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_TDSYZ='" & Trim(Text2) & "'", Mycn
If Myrs1.BOF And Myrs1.EOF Then
MsgBox "不存在土地使用者!!!", vbOKOnly + vbExclamation, "信息提示"

Text2 = ""
Text2.SetFocus
Myrs1.Close
Set Myrs1 = Nothing
Mycn.Close
Exit Sub
End If
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
MSHFlexGrid1.Text = Myrs1.Fields("DCT_BH") & ""
MSHFlexGrid1.Col = 1
.....................
Myrs1.Close
Set Myrs1 = Nothing
Else
Mycn.Close '关闭连接对象
Set Mycn = Nothing
Myrs1.Close
Set Myrs1 = Nothing
Exit Sub
End If
Mycn.Close
End Sub

主要是修改了option1中的连接对象部分,就是mycn.close等语句。你再好好看看。
如果你后面还有option3的话,option2部分那么也按option1部分的修改。
也就是连接对象的关闭要在最后关闭,也就是说在整个command1命令执行要结束的时候才关闭它。

回复
chenyu5188 2003-04-03
新出的问题什么??说的详细些
如哪一行出错?出错代码是什么?
回复
bluesanke 2003-04-03
Option Explicit
Dim Mycn As New ADODB.Connection '数据库连接对象,用于打开数据库
Dim Myrs1 As New ADODB.Recordset '记录集对象,用于存入记录的
Dim Myrs2 As New ADODB.Recordset '记录集对象,用于存入记录的
Private Sub Command1_Click()
Dim cnstring As String '用于存放连接字符串的
cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd"
Mycn.Open cnstring
Mycn.CursorLocation = adUseClient
If Option1.Value = True Then
If Text1.Text = "" Then
MsgBox "请正确填写申请书编号!", vbOKOnly + vbExclamation, "信息提示"
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
If Myrs1.BOF And Myrs1.EOF Then
MsgBox "不存在申请书编号!!!", vbOKOnly + vbExclamation, "信息提示"

Text1 = ""
Text1.SetFocus
Myrs1.Close
Set Myrs1 = Nothing
Mycn.Close
Exit Sub
End If
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
MSHFlexGrid1.Text = Myrs1.Fields("DCT_BH") & ""
MSHFlexGrid1.Col = 1
.....................
Myrs1.Close
Set Myrs1 = Nothing
Else
Mycn.Close '关闭连接对象
Set Mycn = Nothing
Myrs1.Close
Set Myrs1 = Nothing
Exit Sub
Mycn.Close
End If
Mycn.Close
End Sub
改成这样测试通过!
但是新问题有来了

在后面加
If Option2.Value = True Then
If Text2.Text = "" Then
MsgBox "请正确填写土地使用者!", vbOKOnly + vbExclamation, "信息提示"
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_TDSYZ='" & Trim(Text2) & "'", Mycn
If Myrs1.BOF And Myrs1.EOF Then
MsgBox "不存在土地使用者!!!", vbOKOnly + vbExclamation, "信息提示"

Text2 = ""
Text2.SetFocus
Myrs1.Close
Set Myrs1 = Nothing
Mycn.Close
Exit Sub
End If
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
MSHFlexGrid1.Text = Myrs1.Fields("DCT_BH") & ""
MSHFlexGrid1.Col = 1
.....................
Myrs1.Close
Set Myrs1 = Nothing
Else
Mycn.Close '关闭连接对象
Set Mycn = Nothing
Myrs1.Close
Set Myrs1 = Nothing
Exit Sub
Mycn.Close
End If
Mycn.Close
End Sub
有问题呢????!!!


回复
chenyu5188 2003-04-03
因为你第一次使用的记录没有关闭,你要在程序结束时加一个关闭记录集的语句。
在你新贴的代码上修改了:
Option Explicit
Dim Mycn As ADODB.Connection '数据库连接对象,用于打开数据库
Dim Myrs1 As ADODB.Recordset '记录集对象,用于存入记录的
Dim cnstring As String '用于存放连接字符串的
Private Sub Command1_Click()
Set Mycn=New ADODB.Connection
Set Myrs1=New ADODB.Recordset
cnstring = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=dytd;PassWord=dytd;Data Source=dytd"
Mycn.Open cnstring
Mycn.CursorLocation = adUseClient
If Option1.Value = True Then
If Text1.Text = "" Then
MsgBox "请正确填写申请书编号!", vbOKOnly + vbExclamation, "信息提示"
Text1.SetFocus
Exit Sub
Else
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
if myrs1.bof and myrs1.eof then
MsgBox "不存在申请书编号!!!", vbOKOnly + vbExclamation, "信息提示"
Text1 = ""
Text1.SetFocus
Myrs1.close
set myrs1=Nothing
Exit Sub
end if
MSHFlexGrid1.Clear
TableInit
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Col = 0
................................
................................
................................
MSHFlexGrid1.Text = Myrs1.Fields("DCT_TH") & ""
MSHFlexGrid1.Col = 42
MSHFlexGrid1.Text = Myrs1.Fields("DCT_DH") & ""
End If
Myrs1.close
set myrs1=Nothing
Else
Mycn.clsoe'关闭连接对象
Set mycn=nothing
Myrs1.close'关闭记录集对象
Set myrs1=Nothing
Exit Sub
End If
End Sub

以上修改你再再结合你的程序仔细看看,有可能不符你程序的地方,你可以在上面修改。
还有问题的话发短信给我。
回复
hj0849cn 2003-04-03
在exit sub 之前加上
mycn.close
myrsl.close
或者
set mycn=nothing
set myrsl=nothing
回复
饮水需思源 2003-04-03
Myrs1.Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
这句前加上:if myrs1.state=adstateopen then myrs1.close
回复
AechoJohn 2003-04-03
set myrs1 = New ADODB.Recordset
Myrs1.Open Open "select * from DJ_CSDJ_TDDJSQS where DCT_BH='" & Trim(Text1) & "'", Mycn
回复
xsp 2003-04-03
Mycn和Myrs1用完了要记得关闭。
回复
发帖

1183

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2003-04-03 03:05
社区公告
暂无公告