jvcoach23 Posted September 23, 2004 Posted September 23, 2004 try to explain this. I'm trying to pass a value from 1 form to a second. I'm able to do this fine, but get an error when I try to populate the gird. from form 1 Dim WithEvents frmAvantisLast7Days As New frmAvantisLast7Days frmAvantisLast7Days = New frmAvantisLast7Days("Last7Days") 'frmAvantisLast7Days = New frmAvantisLast7Days frmAvantisLast7Days.Show() from form2 Private Sub frmAvantisLast7Days_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If cmdbutton1 = 1 Then subLast24Hours() Else subLast7Days() End If End Sub Sub New(ByVal cmdButton As String) If cmdButton = "cmdLast24Hours" Then cmdbutton1 = 1 Else : cmdbutton1 = 2 End If End Sub Sub subLast7Days() Dim cn As SqlConnection cn = New SqlConnection("server=ntdb1;database=powertools;trusted_connection=true") Dim da As SqlDataAdapter = New SqlDataAdapter("spBreakdownByDayResponse_ForLast7days", cn) Dim ds As New DataSet Try cn.Open() da.SelectCommand.ExecuteNonQuery() cn.Close() da.Fill(ds, "spBreakdownByDayResponse_ForLast7days") Me.dgLast7Days.DataSource = ds Me.dgLast7Days.DataMember = "spBreakdownByDayResponse_ForLast7days" Catch ex As Exception Throw ex End Try End Sub I think I included everything to troubleshoot this. The form 2 works great as long as I don't have the frmAvantisLast7Days = New frmAvantisLast7Days("Last7Days") and only have frmAvantisLast7Days Oh yea.. here is the error An unhandled exception of type 'System.NullReferenceException' occurred in SqlWatch.exe Additional information: Object reference not set to an instance of an object. appreciate any help.. I don't want to create two forms.. I just want teh data back, unformatted in a grid. thanks Shannon Quote JvCoach23 VB.Net newbie MS Sql Vet
Administrators PlausiblyDamp Posted September 23, 2004 Administrators Posted September 23, 2004 Which line generates the error? The error indicates that you are trying to reference a variable that is set to nothing - may be worth stepping through in the debugger and see which objects are not being instantiated. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jvcoach23 Posted September 24, 2004 Author Posted September 24, 2004 Here is teh line that generates teh error. Me.dgLast7Days.DataSource = ds what really confuses me is why this error only happens when I pass value from form 1 to form 2. Why does that make a difference. thanks shannon Quote JvCoach23 VB.Net newbie MS Sql Vet
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.