Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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
Posted
Updated 29-Sep-11 4:45am
v2
Comments
Marc A. Brown 29-Sep-11 10:48am    
Please trim your code down to just the essentials for diagnosing the issue. Also, please provide some more information about the nature of the problem -- error messages, if any; the point in the code where the issue occurs; that sort of thing. Telling us that you're "having a problem..." doesn't give us anything to go on.
Madiha Ahmed 1-Oct-11 10:23am    
Ok.. the problem is that I don't now how to check if a particular exists in my Access database. Can I use IF Exists statement for this purpose??
Tom Deketelaere 5-Oct-11 5:03am    
Your best bet is to query the table with a select and see if it returns anything.
Pseudo code:
"SELECT ipaddress FROM addresses WHERE ipaddress=@address"
(The @address is a parameter so you'll need to make a oledbparameter and add it to your command, this is to prevent sql injection)

1 solution

please add update command on form close event
for ip check use dbcommand with command tex = "SELECT * FROM tblIP Where ip = '000.000.000.000'"
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900