PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
ping in vb error-VBForums
Results 1 to 5 of 5

Thread: ping in vb error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    98

    ping in vb error

    i have the following code but when i select button1 i get the following error: Null Reference Exception was unhandled-object reference not set to an instance of an object. - any idea's how to fix it ??
    *i have underlined the line of code that is highligted when the error occurs

    Code:
    Imports System.Data
    
    
    Public Class Form1
    
        Dim Ping As Net.NetworkInformation.Ping
        Dim pReply As Net.NetworkInformation.PingReply
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Public Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
            Dim sql As String
    
          
    
    
            Dim con As New OleDb.OleDbConnection
            con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mhorgan\Desktop\VBtest.mdb"
            con.Open()
    
            sql = "SELECT * FROM tblone"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "monitor")
    
    
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Ping = New Net.NetworkInformation.Ping
    
                pReply = Ping.Send("143.239.167.240")
    
                Label1.Text = pReply.Status.ToString
    
    
    
    
                If pReply.Status = Net.NetworkInformation.IPStatus.Success Then
                    Dim ds As New DataSet
                    Dim da As OleDb.OleDbDataAdapter
                    Dim sql As String
    
    
    
    
    
    
                    Dim con As New OleDb.OleDbConnection
                    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mhorgan\Desktop\VBtest.mdb"
                    con.Open()
    
                    sql = "SELECT * FROM tblone"
                    da = New OleDb.OleDbDataAdapter(sql, con)
                    da.Fill(ds, "monitor")
    
    
                    Dim cb As New OleDb.OleDbCommandBuilder(da)
    
                    ds.Tables("monitor").Rows(0).Item(1) = Label1.Text
    
                    da.Update(ds, "monitor")
    
    
    
    
    
    
    
                Else
                    Label1.BackColor = Color.Red
                End If
    
            Catch ex As Exception
    
                MessageBox.Show(ex.InnerException.Message)
            End Try
        End Sub
    
        
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            Dim con As New OleDb.OleDbConnection
            con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mhorgan\Desktop\VBtest.mdb"
            con.Close()
            End
    
        End Sub
    End Class
    Last edited by markhorgan1; Jul 8th, 2009 at 03:52 AM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,705

    Re: ping in vb error

    You are assuming that the exception that is thrown initially has an inner exception. Apparently it doesn't. While debugging you should simply do this:
    vb Code:
    1. MessageBox.Show(ex.ToString())
    and you'll get basically all available information.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    98

    Resolved Re: ping in vb error

    works now ! thanks !

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    98

    Re: ping in vb error

    i have tried altering the code and am now gettin another error.instead of having the ip address hardcoded in to the code i want it to be read in from the access db but im now getting this error:System.nullreferenceExceptionbject reference not set to an instance of an object at...button1.click event args e
    i have underlined the piece of code i tried to change

    Code:
    Imports System.Data
    
    
    Public Class Form1
    
        Dim Ping As Net.NetworkInformation.Ping
        Dim pReply As Net.NetworkInformation.PingReply
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
       
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
            Dim sql As String
            Dim con As New OleDb.OleDbConnection
    
    
            Try
                Ping = New Net.NetworkInformation.Ping
    
                pReply = Ping.Send(ds.Tables("monitor").Rows(0).Item(0))
    
                Label1.Text = pReply.Status.ToString
    
    
    
    
                If pReply.Status = Net.NetworkInformation.IPStatus.Success Then
    
    
                    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mhorgan\Desktop\VBtest.mdb"
                    con.Open()
    
                    sql = "SELECT * FROM tblone"
                    da = New OleDb.OleDbDataAdapter(sql, con)
                    da.Fill(ds, "monitor")
    
    
                    Dim cb As New OleDb.OleDbCommandBuilder(da)
    
                    ds.Tables("monitor").Rows(0).Item(1) = Label1.Text
    
                    da.Update(ds, "monitor")
    
    
    
    
    
    
    
                Else
                    Label1.BackColor = Color.Red
                End If
    
            Catch ex As Exception
    
                MessageBox.Show(ex.ToString())
    
            End Try
        End Sub
    
    
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            Dim con As New OleDb.OleDbConnection
            con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\mhorgan\Desktop\VBtest.mdb"
            con.Close()
            End
    
        End Sub
    End Class

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,705

    Re: ping in vb error

    It looks like you're trying to read data from the DataTable before you even populate it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width