I have a program that discover the network..and give IP addresses of the active computers..now I want to connect my program with MS access database..in my database I added the IP addresses..but I want to update my database everytime I debug my program..i want my database to check if IP address is already in it if yes then check its status and depending on the status update the database(0 in the case of off and 1 in case of active)..and if IP address is not already present then add that in the database..and do the same with every IP addresse that my Network Monitor program has discovered ..m having problem in updating my databse and check if IP addresse are already present
Here is the Code
Imports Microsoft.Win32
Imports System.Net.NetworkInformation
Imports System.Threading
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Data
Public Class NetworkDiscovery
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim ObjListCpm As AllNetworkComputers
Dim objsysInfo As New SystemInfo()
Private Sub NetMonitor_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Wgroup = objsysInfo.GetDomain()
ObjListCpm = New AllNetworkComputers(Wgroup, TVComputers, PnlComps)
ObjListCpm.ListComputers()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For Each Nc As ComputersSpecifications In PnlComps.Controls
ObjListCpm = New AllNetworkComputers(Nc.MachineName, chkSts(Nc.MachineName), PnlComps)
ObjListCpm.CheckStatus()
Next
End Sub
Private Sub ScanNetworkToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScanNetworkToolStripMenuItem.Click
Wgroup = objsysInfo.GetDomain()
ObjListCpm = New AllNetworkComputers(Wgroup, TVComputers, PnlComps)
ObjListCpm.ListComputers()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub TVComputers_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TVComputers.MouseClick
Dim SelItm As String = TVComputers.SelectedNode.Text
If e.Button = Windows.Forms.MouseButtons.Right Then
TVComputers.ContextMenuStrip = CMSCompTv
CMSCompTv.Show(e.X, e.Y)
Dim SelNode As TreeNode
SelNode = TVComputers.GetNodeAt(e.X, e.Y)
TVComputers.SelectedNode = SelNode
End If
End Sub
Private Sub CheckStateNowToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckStateNowToolStripMenuItem1.Click
ObjListCpm = New AllNetworkComputers(TVComputers.SelectedNode.Text, chkSts(TVComputers.SelectedNode.Text), PnlComps)
ObjListCpm.CheckStatus()
End Sub
Private Sub CheckAllServersNowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckAllServersNowToolStripMenuItem.Click
For Each Nc As ComputersSpecifications In PnlComps.Controls
ObjListCpm = New AllNetworkComputers(Nc.MachineName, chkSts(Nc.MachineName), PnlComps)
ObjListCpm.CheckStatus()
Next
End Sub
Private Sub CheckStateNowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckStateNowToolStripMenuItem.Click
ObjListCpm = New AllNetworkComputers(TVComputers.SelectedNode.Text, chkSts(TVComputers.SelectedNode.Text), PnlComps)
ObjListCpm.CheckStatus()
End Sub
Private Function chkSts(ByVal Comp As String) As String
Dim Status As String = ""
For Each Nc As ComputersSpecifications In PnlComps.Controls
If Nc.MachineName = Comp Then
If Nc.Status = ComputersSpecifications.UserStatus.Offline Then
Status = "OffLine"
Else
Status = "Online"
End If
End If
Next
Return Status
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:\Documents and Settings\jj\Desktop\IPAddress.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM tblIP"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "IPAddress")
con.Close()
End Sub
End Class