|
-
Jul 8th, 2009, 03:26 AM
#1
Thread Starter
Lively Member
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.
-
Jul 8th, 2009, 04:05 AM
#2
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:
MessageBox.Show(ex.ToString())
and you'll get basically all available information.
-
Jul 8th, 2009, 04:13 AM
#3
Thread Starter
Lively Member
Re: ping in vb error
-
Jul 8th, 2009, 05:24 AM
#4
Thread Starter
Lively Member
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.nullreferenceException bject 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
-
Jul 8th, 2009, 06:43 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|