bonsoir,
Une erreur de syntaxe est apparu lors de l'exécution du code de cette form :

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
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
  Private Sub ESPECE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ESPECE.Click
    TextRecu.Text = ""
    TextBox1.Text = "ESPECE"
  End Sub
 
  Private Sub CARTEB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CARTEB.Click
    TextBox1.Text = "Carte Bancaire"
    TextRecu.Text = TextNet.Text
  End Sub
 
  Private Sub CHEQUE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CHEQUE.Click
    TextBox1.Text = "CHEQUE"
  End Sub
 
  Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    Me.DataGridView1.Rows.Insert(0, New String() {"'" & TextBox1.Text & "'", "'" & TextRecu.Text & "'"})
    Dim a, r As Integer
    a = Val(TextRecu.Text)
    r = a - Val(TextNet.Text)
 
    If r < 0 Then
      TextRecu.Text = -CStr(r)
      TextNet.Enabled = True
 
      TextNet.Text = -CStr(r)
      TextNet.Enabled = False
      TextRecu.Text = -CStr(r)
 
    End If
 
 
  End Sub
 
  Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
 
    Dim cnx As New SqlConnection("Data Source=PC\SQLEXPRESS;Initial Catalog=Fournisseur;Integrated Security=True;Pooling=False;")
    cnx.Open()
    Dim val, val2 As String
 
    val = DataGridView1.Rows(0).Cells(0).Value.ToString
 
    val2 = DataGridView1.Rows(0).Cells(1).Value.ToString
 
    Dim cmd As New SqlCommand("insert into Ticket (TypeReg1,Reçu1) values ('" & val & "', '" & val2 & "')", cnx)
    cmd.ExecuteNonQuery() ' erreur de syntaxe 'ESPECE'.
  End Sub
End Class



cette exception apparait quelque soit la valeur du TextBox1 : ESPECE, Carte Bancaire ou CHAEQUE