Please help with this Error message:
Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object variable or With block variable not set.
Source Error:
Line 38: dbCommand = New SqlCommand("sp_DisplayCommiteeInformation", DataConn)
Line 39: DataConn.Open()
Line 40: dgCommitee.datasource = dbCommand.ExecuteReader(CommandBehavior.CloseConne ction)
Line 41: dgCommitee.databind()
Line 42: 'DataConn.Close()
Source File: c:\inetpub\wwwroot\AIA\AIA\Commitee.aspx.
vb Line: 40
Stack Trace:
[NullReferenceException: Object variable or With block variable not set.]
Microsoft.VisualBasic.CompilerServices.LateBinding .InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType) +1661
Microsoft.VisualBasic.CompilerServices.LateBinding .LateSet(Object o, Type objType, String name, Object[] args, String[] paramnames) +28
AIA.Commitee.BindCommiteeInfo() in c:\inetpub\wwwroot\AIA\AIA\Commitee.aspx.
vb:40
AIA.Commitee.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\AIA\AIA\Commitee.aspx.
vb:26
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
---------------------------------------------------
My code:
Sub BindCommiteeInfo()
Dim myConnection As New SqlConnection()
Dim SQLServer As String = "server=localhost;database=AIA;Trusted_Connection= yes"
Dim DataConn As SqlConnection
Dim dbCommand As SqlCommand
DataConn = New SqlConnection(SQLServer)
Dim dgCommitee
dbCommand = New SqlCommand("sp_DisplayCommiteeInformation", DataConn)
DataConn.Open()
dgCommitee.datasource = dbCommand.ExecuteReader(CommandBehavior.CloseConne ction)
dgCommitee.databind()
'DataConn.Close()
End Sub
Sanjeet