<AttributeUsage(AttributeTargets.Assembly)> _
Public Class ExcuteIdle
Dim cn As SqlConnection
<Browsable(True) > _
Sub New(ByVal strconnection As String)
cn = New SqlConnection(strconnection)
End Sub
'<Obsolete("fdsssssssss")> _
<Description("asdfsdafFDS")> _
Public Property az() As String
Get
End Get
Set(ByVal Value As String)
End Set
End Property
<Description("asdfdfs")> _
Public Function backds(ByVal strselect As String) As DataSet '返回dataset
Dim drt As SqlDataAdapter
Dim dstemp As DataSet
Try
cn.Open()
drt = New SqlDataAdapter(strselect, cn)
dstemp = New DataSet()
drt.Fill(dstemp)
Return dstemp
Finally
cn.Close()
End Try
End Function
Public Function BackRecord(ByVal strselect As String) '返回单条记录
Dim cm As New SqlCommand(strselect, cn)
Dim str As String
'Dim dr As SqlDataReader
Try
cn.Open()
'dr = cm.ExecuteReader()
'While dr.Read
' str = dr.Item(strfeild)
'End While
str = CStr(cm.ExecuteScalar())
Return str
Finally
cn.Close()
End Try
End Function
Public Function BackRecord(ByVal strselect As String, ByVal strfeild As String) As String '重载 BackRecordset
Dim cm As New SqlCommand(strselect, cn)
Dim str As String
Dim dr As SqlDataReader
Try
cn.Open()
dr = cm.ExecuteReader()
While dr.Read
str = dr.Item(strfeild)
End While
'str = CStr(cm.ExecuteScalar())
Return str
Finally
dr.Close()
cn.Close()
End Try
End Function
Public Function excucommand(ByVal strsqlexcu As String) As Boolean '运行sql命令
Dim cm As SqlCommand
Try
cn.Open()
cm = New SqlCommand(strsqlexcu, cn)
cm.ExecuteNonQuery()
Return True
Finally
cn.Close()
End Try
End Function
Public Function Trainexcu(ByVal str1 As String, ByVal str2 As String) As Boolean '进行事务处理
Dim train As SqlTransaction
Dim cm1 As New SqlCommand(str1, cn)
Dim cm2 As New SqlCommand(str2, cn)
cn.Open()
train = cn.BeginTransaction()
cm1.Transaction = train
cm2.Transaction = train
Try
cm1.ExecuteNonQuery()
cm2.ExecuteNonQuery()
train.Commit()
Return True
Catch e As SqlException
train.Rollback()
Throw e
Finally
cn.Close()
End Try
End Function
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class