How to declare global vara that used in any functions except in class

Dear all:
How to declare variable which can be used in multiple function, except define at Class level, and thkx to previous answer, tkx again

Public class1 class

Function1
...
myconnection.open
Dim trans As SqlTransaction = myconnection.BeginTransaction -----------> the trans is defined here after open and cannot define at class since error found in runtine if dim before open connection

Dim updatedetail As New SqlCommand
updatedetail.Connection = myconnection
updatedetail.Transaction = trans
...
Function2(temp1)
Function2(temp2)
trans.commit
....
End Function1

Function2(Byval wk_temp as string)
...
try
updatedetail.CommandText = "Update staff_info set AL_temp = '"& wk_temp & "'"
updatedetail.ExecuteNonQuery()
Catch ex As Exception
trans.Rollback() ---------------------> since the trans here is defined at function1, thus error of undefined
Return False
End Try
.......
End Function2

End Class


Your kindly assistance is highly appreciate....
George


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion