Bonjour,

Nous réalisons actuellement un projet sur Visual Basic et nous rencontrons quelques difficultés.

En fait, nous souhaitons extraire un champ d'une base de données Access et le faire s'afficher dans un TextBox. Serait-il possible que vous nous éclairiez?


Voici notre 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
blic Class FormMedecin
 
    Dim str As String = ""
    Public numeroCarte As String = ""
    Dim rc, rc1 As Byte
    Dim tag_reader_type() As Byte = {&H76, &H3}  'Hitag1 ou Hitag S
    Dim tag_version() As Byte = {&H7A, &H7A}
    Dim read_tag_page() As Byte = {&H52, &H0}
    Dim buf(255) As Byte
    Dim c As Char
 
 
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
 
    End Sub
 
    Private Sub FormMedecin_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    End Sub
 
    Private Function lecture()
        Dim rc As Byte
        Try
            rc = Form1.SerialPort1.ReadByte()
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.OkOnly, "Erreur lecture ligne série")
 
        End Try
 
        Return rc
    End Function
 
 
    Private Sub btnFini_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFini.Click
        Form1.btnLectureCarte.Enabled = True
 
        Me.Close()
    End Sub
 
    Private Sub FormMedecin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO*: cette ligne de code charge les données dans la table 'Bd3DataSet.Requete_médecin'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
        Me.OleDbDataAdapter1.Fill(Me.DataSet21.Médecin)
        Form1.numeroCarte = ""
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer = 0
 
        Try
            Do
 
            Loop While (Form1.SerialPort1.CtsHolding = False)
 
            Form1.SerialPort1.Write(tag_reader_type, 0, 2)
            rc = lecture()
            Do
 
            Loop While (Form1.SerialPort1.CtsHolding = False)
 
            Form1.SerialPort1.Write(tag_version, 0, 1)
            'cpt = SerialPort1.ReceivedBytesThreshold()
            i = 0
            Do
                Do
 
                Loop While (Form1.SerialPort1.CtsHolding = False)
                rc = lecture()
                buf(i) = rc
                c = Convert.ToChar(buf(i))
                str = String.Concat(str, c.ToString())
                i = i + 1
 
            Loop While rc <> 0
 
 
            TextBox4.Text = str
 
            Form1.SerialPort1.Write(read_tag_page, 0, 2)
            Do
 
            Loop While (Form1.SerialPort1.CtsHolding = False)
            rc = lecture()
            rc = rc And &HC6
 
            If (rc = &HC6) Then
                TextBox5.Text = "Data Ok"
                i = 0
                Do
                    str = ""
                    Do
                    Loop While (Form1.SerialPort1.CtsHolding = False)
                    rc = lecture()
                    rc1 = rc
                    rc = rc >> 4
                    rc = rc And &HF
                    numeroCarte = String.Concat(numeroCarte, Hex(rc).ToString())
 
                    rc = rc1 And &HF
                    numeroCarte = String.Concat(numeroCarte, Hex(rc).ToString())
                    i = i + 1
                Loop While i <> 5
                ListBox2.Items.Add(numeroCarte)
 
 
 
                Button1.Enabled = False
 
            Else
                TextBox5.Text = "Data Error"
            End If
 
        Catch ex As Exception
            MsgBox("rien ne marche")
        End Try
 
        'Dim col As DataRow = Me.DataSet21.Tables("Médecin").Rows("CodeCarte1")
 
        Dim ok As Boolean = False
        For Each col As DataRow In Me.DataSet21.Médecin.Rows
            'For j As Integer = 0 To Me.DataSet21.Tables("Médecin").Rows.Count
            For Each lig As DataColumn In Me.DataSet21.Tables("Médecin").Columns
                'Dim row As DataRow = DataSet21.Médecin.Rows(DataRowVersion.Current)
                Dim s As String
                s = lig.ColumnName
                If s = "CodeCarte1" Then
                    s = col(lig, DataRowVersion.Current)
                    If s = numeroCarte Then
                        TextBox5.Text = "Carte Valide"
                        ok = True
                        'afficher la ligne concernée de la colonne 1 dans un text box
                        Exit For
                    Else
                        TextBox5.Text = "Carte rejetée"
                    End If
                End If
 
            'If row("CodeCarte1") = "010825836E" Then
            'row.RowError = "Erreurs dans l’article"
            'End If
            Next
        If ok Then
            Exit For
        End If
        Next


Merci d'avance

Simon, Sophie et Arnaud