Object variable Block variable not set

alexbob18

New member
Joined
Dec 27, 2007
Messages
2
Programming Experience
1-3
Hi. I'm working in a VB.NET project. My problem is in my project i've created a
class clsdatabase where all the connection and executing the query is done. But when i run program the insert and update query runs few times and
later without any change of coding i get "Object variable Block variable not set".

I get this error in the following code..

VB.NET:
dim DbObj = New ClsDatabase
DbObj.ExecuteQuery("Here is the update query")

inside the class clsdatabase

VB.NET:
Public Sub ExecuteQuery(ByVal strSql As String)
        Dim cmd As SqlCommand
        If sqlQryCon.State = ConnectionState.Open Then sqlQryCon.Close()
        cmd = New SqlCommand(strSql, sqlQryCon)
        sqlQryCon.Open()
        cmd.ExecuteNonQuery()
        sqlQryCon.Close()
    End Sub
Why it's happening like this? Please help me rectify this problem. It's making
the whole program not run. Thank u for u'r help in advance.
 
Last edited by a moderator:
Public sqlQryCon As SqlConnection

Public Sub New()
MyBase.New()
sqlQryCon = New SqlConnection(strCon)
End Sub

strCon = I give the connection string

I'm doing this inside the ClsDatabase
 
Last edited:
Back
Top