Bonjour à tous,

voilà j'essaie en vain d'insérer des adresses ip dans une base de données et de les afficher dans un MxDataGrid.

Quelqu'un peut-il m'aider svp?
Bien à vous.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
<%@ Page Language="VB" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Web.Mail" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.DirectoryServices" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Net.DNS" %>
<%@ import Namespace="System.ComponentModel" %>
<%@ import Namespace="System.Management" %>
<%@ import Namespace="System.Runtime.InteropServices" %>
<%@ import Namespace="System" %>
<%@ import Namespace="ActiveDs" %>
<script runat="server">
 
    ' Insert page code here
    '
 
 
     Sub Page_Load()
 
 
            Dim Ldap As DirectoryEntry = New DirectoryEntry("LDAP://tamac.local", "faratbi", "faratbi")
            Dim searcher As DirectorySearcher = New DirectorySearcher(Ldap)
            searcher.Filter = "(objectClass=computer)"
            Dim DirEntry As DirectoryEntry
            Dim nom As String
            Dim OsVersion As String
            Dim Os As String
            Dim ServicePack As String
            Dim Ip As String
 
            SqlDataSourceControl2.ConnectionString="server='(local)'; trusted_connection=true; database='pspintranet'"
            SqlDataSourceControl2.SelectCommand="Select * from Servers"
 
 
            For Each result As SearchResult In searcher.FindAll
 
             DirEntry = result.GetDirectoryEntry
              'Response.Write("Nom : " + DirEntry.Properties("Name").value)
              'Response.write("Os_version : " + DirEntry.Properties("operatingSystemVersion").value)
              'Response.write(" Os : " + DirEntry.Properties("operatingSystem").value)
              'Response.write("ServicePack :" + DirEntry.Properties("operatingSystemServicePack").value)
 
 
 
             nom = DirEntry.Properties("Name").value
             'insertion des ip dans la DB.
             Dim IPHost As IPHostEntry = Dns.Resolve(DirEntry.Properties("Name").value)
             Dim addressList As IPAddress() = IPHost.AddressList
             Dim b As IPAddress = addressList(0) ' récupère la première adresse
             b.ToString()
             'call nslookup(Ip)
             OsVersion    =  DirEntry.Properties("operatingSystemVersion").value
             Os           =   DirEntry.Properties("operatingSystem").value
             ServicePack  =    DirEntry.Properties("operatingSystemServicePack").value
 
             'lblError.Text += nom & " - " & OsVersion & " - " & Os & " - " & ServicePack & "<br>"
                  'Dim IPHost As IPHostEntry = Dns.Resolve(DirEntry.Properties("Name").value)
                  'Dim addressList As IPAddress() = IPHost.AddressList
                  'Dim a As IPAddress = addressList(0) ' récupère la première adresse
 
             call SQLExecuteQuery("INSERT INTO Servers (nom,Ip,ServicePack,OsVersion,OsName) VALUES('"& nom &"','" & b.ToString() & "','" & ServicePack &"','" & OsVersion &"', '" &  Os  &"' )")
 
             Next
 
             MxDataGrid1.DataBind()
 
 
    End Sub
 
    Function SQLExecuteQuery(ByVal sqlQuery As String) As String
 
             Dim a As String
 
             Dim objConnect As New SqlConnection("server='(local)'; trusted_connection=true; database='pspintranet'")
             objConnect.Open()
 
             Dim objCommand As New SqlCommand(sqlQuery, objConnect)
             a = objCommand.ExecuteNonQuery()
             Return a
 
    End Function
 
 
 
 
 
</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <wmx:SqlDataSourceControl id="SqlDataSourceControl2" runat="server" DeleteCommand="" UpdateCommand=""></wmx:SqlDataSourceControl>
        <wmx:MxDataGrid id="MxDataGrid1" runat="server" AllowPaging="True" AllowSorting="True" CellPadding="3" DataKeyField="nom_id" DataSourceControlID="SqlDataSourceControl2" DataMember="Servers" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" BorderStyle="None">
            <FooterStyle backcolor="White" forecolor="#000066"></FooterStyle>
            <HeaderStyle backcolor="#006699" font-bold="True" forecolor="White"></HeaderStyle>
            <ItemStyle forecolor="#000066"></ItemStyle>
            <PagerStyle mode="NumericPages" horizontalalign="Center" backcolor="White" forecolor="#000066"></PagerStyle>
            <SelectedItemStyle backcolor="#669999" font-bold="True" forecolor="White"></SelectedItemStyle>
        </wmx:MxDataGrid>
 
   </form>
</body>
</html>