Bonjour ;
j'ai voulu inserer un enregistrement toujours le meme erreur lors de l'execution.
"le cast spécifié n'est pas valide"
Et voila le code:
ainsi que le module contenant la fonction appelée:
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 Imports System.Data Imports System.Data.OleDb Imports System.Data.OleDb.OleDbCommand Imports System.Data.OleDb.OleDbDataReader Public Class MAJ_Fournisseur Inherits System.Windows.Forms.Form Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click End Sub Private Sub MAJ_Fournisseur_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load module_achat.connecter() End Sub Private Sub vider() Me.TextFodec.Text = "" Me.TextContactFrs.Text = "" Me.TextCodeFrs.Text = "" Me.TextTauRet.Text = "" Me.TextCodeFrs.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Module_connexion.connection() ' If TextCodeFrs.Text <> "" Then Try Ajout("select code_client from CLIENT", Me.TextCodeFrs.Text, "" & _ "Article Déja Existé", "insert into CLIENT values ('" & _ "" & Me.TextCodeFrs.Text & "','" & Me.TextContactFrs.Text & "'," & _ "", "Article Bien Ajouter") Catch ex As Exception MsgBox(ex.Message) End Try vider() ' Else ' MsgBox("Vous Devez remplire tous les chmaps avant d'Ajouter ") ' End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.Close() End Sub End Class
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 Imports System.Data Imports System.Data.OleDb Imports System.Data.OleDb.OleDbConnection Imports System.Data.OleDb.OleDbDataReader Module module_achat Public dr As OleDbDataReader Public strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\GESTION_COMMERCIALE.mdb;Jet OLEDB:Database Password=besmelleh;" Public con As New OleDbConnection(strcon) Public cmd As OleDbCommand Public req As String Public Sub Ajout(ByVal req_verifi As String, ByVal txtbox_verifi As String, ByVal mes_verifi As String, ByVal req_mis_a_j As String, ByVal mes_mis_a_j As String) Try Dim rep As Boolean = False 'execut le select cmd = New OleDbCommand(req_verifi, Module_connexion.cn) dr = cmd.ExecuteReader 'if textbox_verification deja existe rep=true Do While dr.Read If txtbox_verifi.ToLower.Equals(dr.GetString(0).ToLower) Then rep = True End If Loop dr.Close() ' if textbox_verification(c-à-d codeclient) n'existe pas faire l'ajout If rep = False Then Try req = req_mis_a_j cmd = New OleDbCommand(req, Module_connexion.cn) cmd.ExecuteNonQuery() 'MsgBox(req_mis_a_j) Catch ex As Exception MsgBox(ex.Message) End Try Else 'rep=true textbox_verification(c-à-d codeclient) deja existe MsgBox(mes_verifi) End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Public supp_frs Public modif_frs Public Sub connecter() Try If con.State = ConnectionState.Closed Then con.Open() End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Public Sub deconnecter() con.Close() End Sub End Module
Partager