以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  求助。  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=127126)

--  作者:18523500398
--  发布时间:2018/11/6 11:54:00
--  求助。
把事务用在窗口加载的事件,代码如下
try 
Connections(_strBooks).BeginTransaction()
e.Form.BaseForm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
e.Form.DisableXButton()
Dim ma As String 
Dim fo As WinForm.Form = Forms("金相BusMain")
If fo.Opened Then
Dim lvw As WinForm.ListView = Forms("金相BusMain").Controls("LV_SCXX")
Dim vr As WinForm.ListViewRow = lvw.Current \'获取ListView中选定的行
If vr Is Nothing Then \'如果不存在当前行,也就是内有选定任何一行
    Return
End If
Dim dr As DataRow = vr.tag \'获取此行对应的DataRow
e.Form.Controls("TXT_MO").Text = dr("制令单号")
e.Form.Controls("TXT_TI").text=dr("送检单号")
e.Form.Controls("TXT_PRDNAME").Text = dr("货品名称")
e.Form.Controls("TXT_DEP").text=dr("生产线")
e.Form.Controls("TXT_JLNO").text=Vars("_jxlv_jl")
Vars("_jxlv_prdno")=dr("货品编号")
End If
\'\'获得检验项目

\'\'建立表
Dim s As String = Guid.NewGuid.ToString()
Dim cmd1 As new SQLCommand
cmd1.ConnectionName=_strBooks
cmd1.CommandText="EXEC GET_PROJECT_JY \'" & _t1 & "\',\'" & Vars("_jxlv_prdno") & "\',\'" & Date.Now() & "\',\'" & s & "\'"
cmd1.ExecuteNonQuery()
\'\'MessageBox.Show("建立了表成功")

Dim q As new QueryBuilder
q.TableName = "金相临时"
q.ConnectionName=_strBooks
q.SelectString="exec GET_PROJECT_SHOW_TABLE \'" & s & "\'"
q.Build

\'\'MessageBox.Show("查询了表成功")
Dim i As Integer
i=Tables("金相临时").Cols.Count
Vars("_int_tbcount")=i
Dim j As Integer
For j=0 To i-1
    Tables("金相临时").Cols(j).RecordRowHeight=2
Next
\'\'Tables("金相临时").Cols(0).RecordRowHeight=2
Dim rgd As WinForm.RecordGrid = e.Form.Controls("RCDG_R")
Tables("金相临时").AllowEdit=True
rgd.Table=Tables("金相临时")
rgd.Build
\'\'删除表
Dim cmd4 As new SQLCommand
cmd4.ConnectionName=_strBooks
cmd4.CommandText="exec GET_PROJECT_DROP_TABLE \'" & s & "\'"
cmd4.ExecuteNonQuery()
Connections(_strBooks).Commit
catch ex As exception
Connections(_strBooks).Rollback()
MessageBox.Show(ex.Tostring())
End try


然后出错了:
如果分配给命令的连接位于本地挂起事务中,excutereader要求命令拥有事务。命令的transaction属性尚未初始化。


--  作者:有点甜
--  发布时间:2018/11/6 12:07:00
--  

执行存储过程,不能启用事务。

 


--  作者:18523500398
--  发布时间:2018/11/6 12:30:00
--  
好的吧,谢谢有点甜。
--  作者:有点甜
--  发布时间:2018/11/6 14:42:00
--  
如果要用事务,建议你把多个存储过程,合并在一个大的存储过程里面,直接执行这个存储过程。