salut
lorsque je tente a se connecté a sqlserver avec vb.net un message d'erreur se lance :
la referense d'objet n'est pas definie à une instance d'un objet
voila mon code :
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
 
Imports System.Data.SqlClient
 
Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Code généré par le Concepteur Windows Form "
 
    Public Sub New()
        MyBase.New()
 
        'Cet appel est requis par le Concepteur Windows Form.
        InitializeComponent()
 
        'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
 
    End Sub
 
    'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
 
    'Requis par le Concepteur Windows Form
    Private components As System.ComponentModel.IContainer
 
    'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form
    'Elle peut être modifiée en utilisant le Concepteur Windows Form.  
    'Ne la modifiez pas en utilisant l'éditeur de code.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(24, 8)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(288, 17)
        Me.ListBox1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(400, 294)
        Me.Controls.Add(Me.ListBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
 
    End Sub
 
#End Region
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim con As New SqlConnection
        con.ConnectionString = "data source=myidriss;Integrated security=sspi; initial catalog=gestion_aeroport;"
        Dim com As SqlCommand = con.CreateCommand()
        com.CommandText = "select * from avion"
        Try
            con.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
 
        Dim rd As SqlDataReader = com.ExecuteReader()
        Do While rd.Read()
listbox1.items.add(rd.getint32(0))
        Loop
rd.close()
con.close()
 
 
    End Sub
End Class