紧急求救。。。
如果分配给命令的连接位于本地挂起事务中,ExecuteReader 要求命令拥有事务。命令的 Transaction 属性尚未初始化。
Dim Space4Allot As Integer
Dim mycommand As New OdbcCommand
Sqlstr = "select CD_Space4Allot from CmptDisk where CD_ID= ' " & CmptDisk.SelectedValue & " ' "
mycommand.Connection = gConn
mycommand.CommandText = Sqlstr
Dim rea As OdbcDataReader = mycommand.ExecuteReader()
If rea.Read() = True Then
Space4Allot = CInt(rea( "CD_Space4Allot "))
End If
rea.Close()
If CmptName.SelectedItem.Text = "请选择计算机 " Then
Return
ElseIf CustName.SelectedItem.Text = "请选择客户 " Then
Exit Sub
ElseIf Trim(txtCD_totalSpace.Text) = " " Then
Label1.Visible = True
Label1.Text = "总空间不能为空! "
Exit Sub
ElseIf CmptDisk.SelectedItem.Text = "请选择计算机磁盘 " Then
Label1.Visible = True
Label1.Text = "请选择计算机磁盘 "
Exit Sub
Else
Dim mytran As OdbcTransaction
mytran = gConn.BeginTransaction
mycommand.Transaction = mytran
'Try
'检查是否有分区
Dim Str As String = "Select * from CamDiskSpace where CD_ID= ' " & CmptDisk.SelectedValue & " ' and Cmpt_ID= ' " & CmptName.SelectedValue & " ' and CDS_Type= ' " & DiskType.SelectedValue & " ' and Cam_ID= ' " & CamName.SelectedValue & " ' and Cust_ID= ' " & CustName.SelectedValue & " ' "
mycommand.CommandText = Str
Dim das As OdbcDataAdapter = New OdbcDataAdapter(mycommand.CommandText, gConn)
Dim dsset As New DataSet
das.Fill(dsset) ----------这里报错
If dsset.Tables(0).Rows.Count > 0 Then
Label1.Visible = True
Label1.Text = "此计算机此盘已分配空间! "
Exit Sub
Else
'添加镜头磁盘空间记录
Sqlstr = "insert into CamDiskSpace(Cam_ID,CDS_Type,Cust_ID,CD_ID,Cmpt_ID,CDS_Disk,CDS_TotalSpace) values( ' " & CamName.SelectedValue & " ', " _
& " ' " & DiskType.SelectedValue & " ', ' " & CustName.SelectedValue & " ', ' " & CmptDisk.SelectedValue & " ', ' " & CmptName.SelectedValue & " ', ' " & CmptDisk.SelectedItem.Text & " ', ' " & txtCD_totalSpace.Text & " ') "
mycommand.Connection = gConn
mycommand.CommandText = Sqlstr
mycommand.ExecuteNonQuery()
'从计算机磁盘中减少相对应的磁盘空间
Sqlstr = "{call CmptDiskAllot(?,?)} "
mycommand.Connection = gConn
mycommand.CommandText = Sqlstr
mycommand.CommandType = CommandType.StoredProcedure
Dim para As OdbcParameter
para = mycommand.Parameters.Add( "@CD_ID ", OdbcType.BigInt, 8)
para.Direction = ParameterDirection.Input
para.Value = CLng(CmptDisk.SelectedValue)
para = mycommand.Parameters.Add( "@AllotSize ", OdbcType.BigInt, 8)
para.Direction = ParameterDirection.Input
para.Value = CLng(Space4Allot) - CLng(txtCD_totalSpace.Text)
mycommand.ExecuteNonQuery()
mytran.Commit()
BindGridview()
End If
Connection已打开连接。。请高手们帮帮忙!
[解决办法]
mycommand.Connection = gConn
mycommand.CommandText = Sqlstr
mycommand.ExecuteNonQuery()
'从计算机磁盘中减少相对应的磁盘空间
Sqlstr = "{call CmptDiskAllot(?,?)} "
mycommand.Connection = gConn
'加一行
mycommand.Transaction = mytran
mycommand.CommandText = Sqlstr
mycommand.CommandType = CommandType.StoredProcedure
[解决办法]
http://community.csdn.net/Expert/topic/5606/5606692.xml?temp=.1257135
结贴。要分的去,有50