这一段代码不用 cnn.open 吗?为什么

lz_xiaohai 2018-06-04 09:31:42
Private Function Sub_SaveBill() As Boolean '保 存 单 据
Dim rstemp As New ADODB.Recordset
Dim fdate As String
Dim id As String

If Text1(0).Text = "" Then MsgBox ("车牌号没有输入"): Exit Function
If Val(Text1(4).Text) = 0 Then MsgBox ("重量不能为零"): Exit Function
Set rstemp = ExecuteSQL("select 1 from z_bill where 车牌号='" & Text1(0).Text & "' and isnull(制单人2,'')=''", "")
If rstemp.EOF = False Then
MsgBox ("该车牌号已存在记录,不能重复称重")
Exit Function
End If

conn.BeginTrans
On Error GoTo err1
Set rstemp = conn.Execute("exec sp_getbillnumno '" & Date & "','1'")
fbillno = rstemp.Fields(0).Value


conn.Execute "insert into z_bill(单据号,公司,品名,供应商,车牌号,进厂,出厂 ,净重 ,制单人1 ,制单日期1 ,型号) values('" _
& fbillno & "','" & Combo1(2).Text & "','" & Combo1(0).Text & "','" & Combo1(1).Text & "','" & Text1(0).Text & "','" & Val(Text1(4).Text) & "',0,0,'" & LoginName & "',getdate(),'" & Text1(2).Text & "')"
conn.CommitTrans
MsgBox "保存成功"

'Select Case Combo2.Text
'Case "中文合格证"
'Unload frpt1
'With frpt1.adors
'.Connection = conn
'.Source = "select * from V_合格证 Where 条码='" & Text1(9).Text & "'"
'End With
'frpt1.PrintReport False
'Case "COVEME合格证"
'Unload frpt2
'With frpt2.adors
'.Connection = conn
'.Source = "select * from V_合格证 Where 条码='" & Text1(9).Text & "'"
'End With
'frpt2.PrintReport False
'Case "英文合格证"
'Unload frpt3
'With frpt3.adors
'.Connection = conn
'.Source = "select * from V_合格证 Where 条码='" & Text1(9).Text & "'"
'End With
'frpt3.PrintReport False
'End Select
Call Sub_OperStatus("10")
'Text1(4).Text = ""
Sub_SaveBill = True
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
Exit Function
err1:
MsgBox Err.Description
conn.RollbackTrans
End Function

他这一段代码不用 cnn.open 吗?为什么
...全文
693 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lz_xiaohai 2018-06-06
  • 打赏
  • 举报
回复
谢谢,我再查找一下。。。。。
lz_xiaohai 2018-06-04
  • 打赏
  • 举报
回复
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset '功能: 执行后台SQL语句, '参数: SQL:SQL语句,msgstring:运行结果 '返回值: 如果是查询语句则返回记录集 '返回类型:记录集 Dim rst As New ADODB.Recordset Dim mf_conn As New ADODB.Connection Dim sTokens() As String MsgString = "" On Error GoTo ExecuteSQL_Error sTokens = Split(SQL) If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then conn.Execute SQL MsgString = sTokens(0) & " query successful" Else rst.CursorLocation = adUseClient rst.Open Trim$(SQL), conn, adOpenStatic ' MsgBox rst.RecordCount 'rst.MoveLast 'get RecordCount Set ExecuteSQL = rst ' MsgString = "查询到" & rst.RecordCount & " 条记录 " End If ExecuteSQL_Exit: Set rst = Nothing Exit Function ExecuteSQL_Error: MsgBox "查询错误: " & Err.Description Resume ExecuteSQL_Exit End Function 这是 ExecuteSQL函数
脆皮大雪糕 2018-06-04
  • 打赏
  • 举报
回复
看看 ExecuteSQL的定义,是不是已经在那里面检查了cnn的状态并且该open就open掉了
脆皮大雪糕 2018-06-04
  • 打赏
  • 举报
回复
你的cnn是全局变量吧, 全工程搜索一下 cnn.open 看在哪里open了

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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