Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

JvCoach23

VB.Net newbie

MS Sql Vet

Posted

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

JvCoach23

VB.Net newbie

MS Sql Vet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...