IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Lecture base access


Sujet :

VB.NET

  1. #21
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 19
    Points : 18
    Points
    18
    Par défaut
    Je veux enregistrer les information d'enregistrement sur deux table access
    est ce que possible !!
    si oui, comment faire s'il te plait Monsieur ! : )
    (ce code qui ajouter aux une seul table)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Dim savlnto As New OleDb.OleDbCommand
            Dim dtadapter As New OleDbDataAdapter(sql_Patient, maconnection)
            savlnto.Connection = maconnection
            savlnto.CommandType = CommandType.Text
            savlnto.CommandText = "insert into T_Patient(Numero_Patient,CIN_Patient,Nom,Prenom,Date_Naissance,Tele,Sexe,Adresse_Residentiel,Nature_De_Operation,Prix,Paiement,Reset,Enfant_Adult,Dants_Mal,Qustion_Problems,Qustion_Medical1,Qustion_Medica2,Qustion_Medical3,Qustion_Allergie,Qustion_enceinte,Qustion_enceinte_Mois,Medicamment,Remaque_De_Santé,Impression_traitement,Date_Inscription)" & " values ('" & Txt_Num_Patient.Text.Trim & "','" & Txt_CNI.Text.Trim & "','" & Txt_Nom.Text.Trim & "','" & Txt_Prenom.Text.Trim & "','" & DateTimePicker_Naissance.Value.ToString("dd/MM/yyyy").Trim & "','" & Txt_Tele.Text.Trim & "','" & sexe.Trim & "','" & Txt_Adress.Text.Trim & "','" & Cmb_NaturesOperation.Text.Trim & "','" & Txt_Prix.Text.Trim & "','" & Txt_Paiment.Text.Trim & "','" & Txt_Reset.Text.Trim & "','" & Enfant_Adult.Trim & "','" & Trim(Dants_Mal) & "','" & Qustion_Problems & "','" & Txt_SousTraitmentMedicale.Text.Trim & "','" & Txt_PrendMedicament.Text.Trim & "','" & Txt_MedicamentContre.Text.Trim & "','" & Qustion_Allergie & "','" & Txt_Enceinte.Text.Trim & "','" & Txt_Mois.Text.Trim & "','" & Medicamment & "','" & Txt_Remarque.Text.Trim & "','" & Txt_ImprestionTratment.Text.Trim & "','" & DateTimePicker_Inscription.Value.ToString("dd/MM/yyyy").Trim & "')"
            maconnection.Open()
            savlnto.ExecuteNonQuery()
            dtset.Clear()
            dtadapter.Fill(dtset, "T_Patient")
            maconnection.Close()
            MsgBox("votre nouveau enregistrement et bien enregistrer")

  2. #22
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Non Access ne l'autorise pas!

    De plus si ces table sont liés par clé primaire auto-incrément, tu ne connais pas l'identifiant de la clé avant l'insertion.

    Il faut insérer dans la table1 récupérer la clé pour l'utiliser en jointure dans la table2!

  3. #23
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 19
    Points : 18
    Points
    18
    Par défaut
    Comment faire cette methode S'il te plait !!!

  4. #24
    Invité
    Invité(e)
    Par défaut
    bonjour,
    si tu pouvais mettre un base Access sens données confidentielles ce serait cool!

    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    Imports System.Data.OleDb
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim a As SqlMetier = New SqlMetier("C:\Users\rdurupt\Documents\Base de données1.accdb")
            a.OpenConnexion()
            a.Ajouter()
            a.CloseConnexion()
        End Sub
    End Class
    Class Connexion
        Public Structure ParmCmd
            Public Name As String
            Public Type As VarAdodb
            Public Direction As VarAdodb
            Public Size As Long
            Public Value As String
        End Structure
        Public Enum VarAdodb
            adAddNew = 16778240
            adAffectAllChapters = 4
            adAffectCurrent = 1
            adAffectGroup = 2
            adApproxPosition = 16384
            adArray = 8192
            adAsyncConnect = 16
            adAsyncExecute = 16
            adAsyncFetch = 32
            adAsyncFetchNonBlocking = 64
            adBigInt = 20
            adBinary = 128
            adBookmark = 8192
            adBookmarkCurrent = 0
            adBookmarkFirst = 1
            adBookmarkLast = 2
            adBoolean = 11
            adBSTR = 8
            adChapter = 136
            adChar = 129
            adClipString = 2
            adCmdFile = 256
            adCmdStoredProc = 4
            adCmdTable = 2
            adCmdTableDirect = 256
            adCmdText = 1
            adCmdUnknown = 8
            adCollectionRecord = 1
            adCompareEqual = 1
            adCompareGreaterThan = 2
            adCompareLessThan = 0
            adCompareNotComparable = 4
            adCompareNotEqual = 3
            adCopyAllowEmulation = 4
            adCopyNonRecursive = 2
            adCopyOverWrite = 1
            adCopyUnspecified = -1
            adCreateCollection = 8192
            adCreateNonCollection = 0
            adCreateOverwrite = 67108864
            adCreateStructDoc = -2147483648
            adCriteriaAllCols = 1
            adCriteriaKey = 0
            adCriteriaTimeStamp = 3
            adCriteriaUpdCols = 2
            adCRLF = -1
            adCurrency = 6
            adDate = 7
            adDBDate = 133
            adDBTime = 134
            adDBTimeStamp = 135
            adDecimal = 14
            adDefaultStream = -1
            adDelayFetchFields = 32768
            adDelete = 16779264
            adDouble = 5
            adEditAdd = 2
            adEditDelete = 4
            adEditInProgress = 1
            adEditNone = 0
            adEmpty = 0
            adErrBoundToCommand = 3707
            adErrCannotComplete = 3732
            adErrCantChangeConnection = 3748
            adVarChar = 200
            adParamInput = 1
        End Enum
        Public Enum CommAdo
            adCmdFile = 256
            adCmdStoredProc = 4
            adCmdTable = 2
            adCmdTableDirect = 521
            adCmdText = 1
            adCmdU
            nknown = 8
        End Enum
        Private cnx As OleDbConnection = Nothing
        Private _Fichier As String
        Public Sub New(ByVal Fichier As String)
            _Fichier = Fichier
        End Sub
        Public Sub OpenConnexion()
            Dim GenereCSTRING As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _Fichier & ";"
            cnx = New OleDbConnection(GenereCSTRING)
            Try
                cnx.Open()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
        Public Function Execute(ByVal Sql As String) As Object
            Dim myObject As New Object
            Using cmd As New OleDb.OleDbCommand(Sql, cnx)
                Try
                    Return cmd.ExecuteReader()
                Catch ex As Exception
                    Return Nothing
                End Try
            End Using
        End Function
        Public Function Execute(ByVal Sql As String, ByVal Param As Object) As Object
            Dim myObject As New Object
            Using cmd As New OleDb.OleDbCommand(Sql, cnx)
                For Each c As Object In Param
     
                    If c.Size <> 0 Then cmd.Parameters.Add(c.Name, c.Type, c.Size).Value = c.Value
                Next
                Try
                    Return cmd.ExecuteReader()
                Catch ex As Exception
                    Return Nothing
                End Try
            End Using
        End Function
        Public Sub CloseConnexion()
            cnx.Close()
            cnx.Dispose()
            cnx = Nothing
        End Sub
     
    End Class
    Class SqlMetier
        Inherits Connexion
        Public Sub New(ByVal Fichier As String)
            MyBase.New(Fichier)
        End Sub
        Public Sub Ajouter()
            Dim sql As String = "INSERT INTO Table1 ( A, B ) Values(? ,?);"
            Dim prm() As ParmCmd = {New ParmCmd, New ParmCmd}
            prm(0).Name = "@A" : prm(0).Type = VarAdodb.adVarChar : prm(0).Direction = VarAdodb.adParamInput : prm(0).Size = 50 : prm(0).Value = "TOTO"
            prm(1).Name = "@B" : prm(1).Type = VarAdodb.adVarChar : prm(1).Direction = VarAdodb.adParamInput : prm(1).Size = 50 : prm(1).Value = "Vélo"
            Dim obj As OleDb.OleDbDataReader = Execute(sql, prm)
            obj.Read()
            obj.Close() : obj.Dispose()
            sql = "Select Id from Table1 where A=? and B=?"
            obj = Execute(sql, prm)
     
            obj.Read()
            Dim id_Table1 As String = obj.Item("ID").ToString
            prm = {New ParmCmd, New ParmCmd}
            prm(0).Name = "@Id_Table1" : prm(0).Type = VarAdodb.adBigInt : prm(0).Direction = VarAdodb.adParamInput : prm(0).Size = 4 : prm(0).Value = id_Table1
            prm(1).Name = "@Teste" : prm(1).Type = VarAdodb.adVarChar : prm(1).Direction = VarAdodb.adParamInput : prm(1).Size = 50 : prm(1).Value = "Teste"
            sql = "INSERT INTO Table2 ( Id_Table1, Teste ) Values(? ,?);"
            obj = Execute(sql, prm)
            obj.Close() : obj.Dispose()
        End Sub
     
    End Class
    Dernière modification par rv26t ; 12/07/2016 à 18h58. Motif: fusion de messages consécutifs

  5. #25
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 19
    Points : 18
    Points
    18
    Par défaut
    C gentil Monsieur merciiiiiiiiiiiiiiiiiii
    mais j'ai pas le niveau de ce code !
    tu peux me explique s'il te plait !

  6. #26
    Invité
    Invité(e)
    Par défaut
    j'ai créé un une bas de donnée avec des lien entre table:

    Nom : Sans titre.png
Affichages : 536
Taille : 28,6 Ko

    j’ajoute un module de classe Connexion! il me serra utile dans toutes les transaction avec la base de données!

    les structure permettent de garder un Ecriture intuitive
    si tu regardes ce que nous avons déjà écrit tu les retrouves

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Edit_into.CommandType = CommandType.Text
            Edit_into.CommandText = "update T_Patient set Numero_Patient=?,Nom=?,Prenom=?,Date_Naissance=?,Tele=?,Sexe=?,Adresse_Residentiel=?,Nature_De_Operation=?,Prix=?,Paiement=?,Reset=?,Enfant_Adult=?,Dants_Mal=?,Qustion_Problems=?,Qustion_Medical1=?,Qustion_Medica2=?,Qustion_Medical3=?,Qustion_Allergie=?,Qustion_enceinte=?,Qustion_enceinte_Mois=?,Medicamment=?,Remaque_De_Santé=?,Impression_traitement=?,Date_Inscription=? where Nom=?"
            Edit_into.Parameters.Add("@Numero_Patient", OleDbType.VarWChar, 255).Value = Txt_Nom.Text.Trim
            Edit_into.Parameters.Add("@Nom", OleDbType.VarWChar, 255).Value = Txt_Nom.Text.Trim
            Edit_into.Parameters.Add("@Prenom", OleDbType.VarWChar, 255).Value = Txt_Prenom.Text.Trim
            Edit_into.Parameters.Add("@Date_Naissance", OleDbType.VarWChar, 255).Value = DateTimePicker_Naissance.Value.ToString("dd/MM/yyyy")

    Code classe Connexion : 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
    Class Connexion    Public Structure ParmCmd
            Public Name As String
            Public Type As VarAdodb
            Public Direction As VarAdodb
            Public Size As Long
            Public Value As String
     
    je l'ai mis sur la même feulle pour des question patique (ça marche sens problème) mais tu dois les créer séparément c'es mieux!
        End Structure
        Public Enum VarAdodb
            adAddNew = 16778240
            adAffectAllChapters = 4
            adAffectCurrent = 1
            adAffectGroup = 2
            adApproxPosition = 16384
            adArray = 8192
            adAsyncConnect = 16
            adAsyncExecute = 16
            adAsyncFetch = 32
            adAsyncFetchNonBlocking = 64
            adBigInt = 20
            adBinary = 128
            adBookmark = 8192
            adBookmarkCurrent = 0
            adBookmarkFirst = 1
            adBookmarkLast = 2
            adBoolean = 11
            adBSTR = 8
            adChapter = 136
            adChar = 129
            adClipString = 2
            adCmdFile = 256
            adCmdStoredProc = 4
            adCmdTable = 2
            adCmdTableDirect = 256
            adCmdText = 1
            adCmdUnknown = 8
            adCollectionRecord = 1
            adCompareEqual = 1
            adCompareGreaterThan = 2
            adCompareLessThan = 0
            adCompareNotComparable = 4
            adCompareNotEqual = 3
            adCopyAllowEmulation = 4
            adCopyNonRecursive = 2
            adCopyOverWrite = 1
            adCopyUnspecified = -1
            adCreateCollection = 8192
            adCreateNonCollection = 0
            adCreateOverwrite = 67108864
            adCreateStructDoc = -2147483648
            adCriteriaAllCols = 1
            adCriteriaKey = 0
            adCriteriaTimeStamp = 3
            adCriteriaUpdCols = 2
            adCRLF = -1
            adCurrency = 6
            adDate = 7
            adDBDate = 133
            adDBTime = 134
            adDBTimeStamp = 135
            adDecimal = 14
            adDefaultStream = -1
            adDelayFetchFields = 32768
            adDelete = 16779264
            adDouble = 5
            adEditAdd = 2
            adEditDelete = 4
            adEditInProgress = 1
            adEditNone = 0
            adEmpty = 0
            adErrBoundToCommand = 3707
            adErrCannotComplete = 3732
            adErrCantChangeConnection = 3748
            adVarChar = 200
            adParamInput = 1
        End Enum
        Public Enum CommAdo
            adCmdFile = 256
            adCmdStoredProc = 4
            adCmdTable = 2
            adCmdTableDirect = 521
            adCmdText = 1
            adCmdU
            nknown = 8
        End Enum
        Private cnx As OleDbConnection = Nothing
        Private _Fichier As String
        Public Sub New(ByVal Fichier As String)
            _Fichier = Fichier
        End Sub
        Public Sub OpenConnexion()
            Dim GenereCSTRING As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _Fichier & ";"
            cnx = New OleDbConnection(GenereCSTRING)
            Try
                cnx.Open()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
        Public Function Execute(ByVal Sql As String) As Object
            Dim myObject As New Object
            Using cmd As New OleDb.OleDbCommand(Sql, cnx)
                Try
                    Return cmd.ExecuteReader()
                Catch ex As Exception
                    Return Nothing
                End Try
            End Using
        End Function
        Public Function Execute(ByVal Sql As String, ByVal Param As Object) As Object
            Dim myObject As New Object
            Using cmd As New OleDb.OleDbCommand(Sql, cnx)
                For Each c As Object In Param
     
     
                    If c.Size <> 0 Then cmd.Parameters.Add(c.Name, c.Type, c.Size).Value = c.Value
                Next
                Try
                    Return cmd.ExecuteReader()
                Catch ex As Exception
                    Return Nothing
                End Try
            End Using
        End Function
        Public Sub CloseConnexion()
            cnx.Close()
            cnx.Dispose()
            cnx = Nothing
        End Sub
     
     
    End Class
    ce module de classe contient toutes le méthodes utiles pour dialoger avec la base de données!

    vue que ce module nous sera utile pour tout dialogue avec la base de données! mais pour éviter de réécrire ce code, nous dirons aux autre module de classe qu'il hérite de la connexion.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Class SqlMetier
        Inherits Connexion 'Héritage!
    End Class
    sub New est ce que nous appelons un constructeur!
    Hors la classe Connexion doit récupérer le nom et le chemin complet de la base de données Access. hors cette classe est héritée par la classe SqlMetier!

    il faut noter que les bonne pratique impose que les userforms, qui correspondent à la couche client (IHM) ne disposent pas de traitement lien au métier. cela permet le cas échéant de réutiliser une partie du code pour faire un IHM web par exemple.

    donc notre classe SqlMetier hérite de la classe Connexion mais pour lui donner le le nom et le chemin complet de la base de données Access nous utilisons un ascenseur!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Class SqlMetier
        Inherits Connexion
        Public Sub New(ByVal Fichier As String)
            MyBase.New(Fichier) 'ascenseur
        End Sub
    End Class
    la class SqlMetier dispose maintenant de toutes les méthodes de la classe Connecxion.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     Dim sql As String = "INSERT INTO Table1 ( A, B ) Values(? ,?);"
            Dim prm() As ParmCmd = {New ParmCmd, New ParmCmd}
            prm(0).Name = "@A" : prm(0).Type = VarAdodb.adVarChar : prm(0).Direction = VarAdodb.adParamInput : prm(0).Size = 50 : prm(0).Value = "TOTO"
            prm(1).Name = "@B" : prm(1).Type = VarAdodb.adVarChar : prm(1).Direction = VarAdodb.adParamInput : prm(1).Size = 50 : prm(1).Value = "Vélo"
            Dim obj As OleDb.OleDbDataReader = Execute(sql, prm)
    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
    Public Function Execute(ByVal Sql As String, ByVal Param As Object) As Object
            Dim myObject As New Object
            Using cmd As New OleDb.OleDbCommand(Sql, cnx)
                For Each c As Object In Param
     
     
                    If c.Size <> 0 Then cmd.Parameters.Add(c.Name, c.Type, c.Size).Value = c.Value
                Next
                Try
                    Return cmd.ExecuteReader()
                Catch ex As Exception
                    Return Nothing
                End Try
            End Using
        End Function
    c'est la même chose sauf que je rend réutilisable la méthode! elle retourne un OleDb.OleDbDataReader

    le même que tu utilisais là sens le savoir!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      dtAdapter.Fill(dtset, "T_Patient")
    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
      Edit_into.CommandText = "update T_Patient set Numero_Patient=@Numero_Patient,Nom=@Nom,Prenom=@Prenom,Date_Naissance=@Date_Naissance,Tele=@Tele,Sexe=@Sexe,Adresse_Residentiel=@Adresse_Residentiel,Nature_De_Operation=@Nature_De_Operation,Prix=@Prix,Paiement=@Paiement,Reset=@Reset,Enfant_Adult=@Enfant_Adult,Dants_Mal=@Dants_Mal,Qustion_Problems=@Qustion_Problems,Qustion_Medical1=@Qustion_Medical1,Qustion_Medica2=@Qustion_Medica2,Qustion_Medical3=@Qustion_Medical3,Qustion_Allergie=@Qustion_Allergie,Qustion_enceinte=@Qustion_enceinte,Qustion_enceinte_Mois=@Qustion_enceinte_Mois,Medicamment=@Medicamment,Remaque_De_Santé=@Remaque_De_Santé,Impression_traitement=@Impression_traitement,Date_Inscription=@Date_Inscription where Nom=@Nom"
            Edit_into.Parameters.Add("@Numero_Patient", OleDbType.VarWChar, 255).Value = Txt_Nom.Text.Trim
            Edit_into.Parameters.Add("@Nom", OleDbType.VarWChar, 255).Value = Txt_Nom.Text.Trim
            Edit_into.Parameters.Add("@Prenom", OleDbType.VarWChar, 255).Value = Txt_Prenom.Text.Trim
            Edit_into.Parameters.Add("@Date_Naissance", OleDbType.VarWChar, 255).Value = DateTimePicker_Naissance.Value.ToString("dd/MM/yyyy")
            Edit_into.Parameters.Add("@Tele", OleDbType.VarWChar, 255).Value = Txt_Tele.Text.Trim
            Edit_into.Parameters.Add("@sexe", OleDbType.VarWChar, 255).Value = sexe.Trim
            Edit_into.Parameters.Add("@Adresse_Residentiel", OleDbType.VarWChar, 255).Value = Txt_Adress.Text.Trim
            Edit_into.Parameters.Add("@Nature_De_Operation", OleDbType.VarWChar, 255).Value = Cmb_NaturesOperation.Text.Trim
            Edit_into.Parameters.Add("@Prix", OleDbType.Integer, 255).Value = Txt_Prix.Text.Trim
            Edit_into.Parameters.Add("@Paiement", OleDbType.Integer, 255).Value = Txt_Paiment.Text.Trim
            Edit_into.Parameters.Add("@Reset", OleDbType.Integer, 255).Value = Txt_Reset.Text.Trim
            Edit_into.Parameters.Add("@Enfant_Adult", OleDbType.VarWChar, 255).Value = Enfant_Adult.Trim
            Edit_into.Parameters.Add("@Dants_Mal", OleDbType.VarWChar, 255).Value = Dants_Mal.Trim
            Edit_into.Parameters.Add("@Qustion_Problems", OleDbType.VarWChar, 255).Value = Qustion_Problems.Trim
            Edit_into.Parameters.Add("@Qustion_Medical1", OleDbType.VarWChar, 255).Value = Txt_SousTraitmentMedicale.Text.Trim
            Edit_into.Parameters.Add("@Qustion_Medica2", OleDbType.VarWChar, 255).Value = Txt_PrendMedicament.Text.Trim
            Edit_into.Parameters.Add("@Qustion_Medical3", OleDbType.VarWChar, 255).Value = Txt_MedicamentContre.Text.Trim
            Edit_into.Parameters.Add("@Qustion_Allergie", OleDbType.VarWChar, 255).Value = Qustion_Allergie.Trim
            Edit_into.Parameters.Add("@Qustion_enceinte", OleDbType.VarWChar, 255).Value = Txt_Enceinte.Text.Trim
            Edit_into.Parameters.Add("@Qustion_enceinte_Mois", OleDbType.VarWChar, 255).Value = Txt_Mois.Text.Trim
            Edit_into.Parameters.Add("@Medicamment", OleDbType.VarWChar, 255).Value = Medicamment.Trim
            Edit_into.Parameters.Add("@Remaque_De_Santé", OleDbType.VarWChar, 255).Value = Txt_Remarque.Text.Trim
            Edit_into.Parameters.Add("@Impression_traitement", OleDbType.VarWChar, 255).Value = Txt_ImprestionTratment.Text.Trim
            Edit_into.Parameters.Add("@Date_Inscription", OleDbType.VarWChar, 255).Value = Txt_ImprestionTratment.Text.Trim
            maconnection.Open()
            Edit_into.ExecuteNonQuery()
    maintenant prenons des exemples:

    Code comme dans le poste 5 : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    sql = "Dim SQL_rech AsString = "select * From T_Patient where Nom like '" & rech & "'"dtred= Execute(sql, prm)
    dtred
     If dtred.Read = True Then
                Txt_CNI.Text = dtred.Item(1).ToString
                Txt_Nom.Text = dtred.Item(2).ToString
                Txt_Prenom.Text = dtred.Item(3).ToString
                DateTimePicker_Naissance.Value = dtred.Item(4).ToString
                Txt_Tele.Text = dtred.Item(5).ToString
                sx = Trim(dtred.Item(6).ToString)

    Code comme dans le poste 9 : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     Execute("insert into T_Patient(Numero_Patient,CIN_Patient,Nom,Prenom,Date_Naissance,Tele,Sexe,Adresse_Residentiel,Nature_De_Operation,Prix,Paiement,Reset,Enfant_Adult,Dants_Mal,Qustion_Problems,Qustion_Medical1,Qustion_Medica2,Qustion_Medical3,Qustion_Allergie,Qustion_enceinte,Qustion_enceinte_Mois,Medicamment,Remaque_De_Santé,Impression_traitement,Date_Inscription)" & " values (' " & Txt_Num_Patient.Text.Trim & " ',' " & Txt_CNI.Text.Trim & " ',' " & Txt_Nom.Text.Trim & " ',' " & Txt_Prenom.Text.Trim & " ',' " & DateTimePicker_Naissance.Value.ToString("dd/MM/yyyy").Trim & " ',' " & Txt_Tele.Text.Trim & " ',' " & sexe.Trim & " ',' " & Txt_Adress.Text.Trim & " ',' " & Cmb_NaturesOperation.Text.Trim & " ',' " & Txt_Prix.Text.Trim & " ',' " & Txt_Paiment.Text.Trim & " ',' " & Txt_Reset.Text.Trim & " ',' " & Enfant_Adult.Trim & " ',' " & Dants_Mal & " ',' " & Qustion_Problems & " ',' " & Txt_SousTraitmentMedicale.Text.Trim & " ',' " & Txt_PrendMedicament.Text.Trim & " ',' " & Txt_MedicamentContre.Text.Trim & " ',' " & Qustion_Allergie & " ',' " & Txt_Enceinte.Text.Trim & " ',' " & Txt_Mois.Text.Trim & " ',' " & Medicamment & " ',' " & Txt_Remarque.Text.Trim & " ',' " & Txt_ImprestionTratment.Text.Trim & " ',' " & DateTimePicker_Inscription.Value.ToString("dd/MM/yyyy").Trim & " ')")
    Code Classe SqlMetier : 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
    Sub Ajouter()
    'Requête D'insertion
            Dim sql As String = "INSERT INTO Table1 ( A, B ) Values(? ,?);"
            Dim prm() As ParmCmd = {New ParmCmd, New ParmCmd}
            prm(0).Name = "@A" : prm(0).Type = VarAdodb.adVarChar : prm(0).Direction = VarAdodb.adParamInput : prm(0).Size = 50 : prm(0).Value = "TOTO"
            prm(1).Name = "@B" : prm(1).Type = VarAdodb.adVarChar : prm(1).Direction = VarAdodb.adParamInput : prm(1).Size = 50 : prm(1).Value = "Vélo"
            Dim obj As OleDb.OleDbDataReader = Execute(sql, prm)
            obj.Close() : obj.Dispose()
    '*****************************************************************************************
    'Requête de selection le where reçoit le même valeur que le Insert
            sql = "Select Id from Table1 where A=? and B=?" 'Table1  est L'identifiant de liaison entre les  2 table 
            obj = Execute(sql, prm)
            obj.Read() 'je lis le résultat comme tu l'as déjà fait!
     
            Dim id_Table1 As String = obj.Item("ID").ToString 'et j’affecte la valeur à une string!
    '*********************************************************************************************************************
    'maintenant je peux inserer dans ma table fille! 
            prm = {New ParmCmd, New ParmCmd}
            prm(0).Name = "@Id_Table1" : prm(0).Type = VarAdodb.adBigInt : prm(0).Direction = VarAdodb.adParamInput : prm(0).Size = 4 : prm(0).Value = id_Table1
            prm(1).Name = "@Teste" : prm(1).Type = VarAdodb.adVarChar : prm(1).Direction = VarAdodb.adParamInput : prm(1).Size = 50 : prm(1).Value = "Teste"
            sql = "INSERT INTO Table2 ( Id_Table1, Teste ) Values(? ,?);"
            obj = Execute(sql, prm)
            obj.Close() : obj.Dispose()
        End Sub
    et là je l'utilise sur l’événement Load de mon UserForm
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim a As SqlMetier = New SqlMetier("C:\Users\rdurupt\Documents\Base de données1.accdb")
            a.OpenConnexion()
            a.Ajouter()
            a.CloseConnexion()
        End Sub
    dans mon code on trouve 3 module de classe:
    Public Class Form1
    Public Class Connexion
    Public Class SqlMetier
    Dernière modification par Invité ; 23/05/2016 à 16h52.

  7. #27
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 19
    Points : 18
    Points
    18
    Par défaut
    Merci Merci Merci Merci Merci
    et en arabe
    شكراااااااااااااااااااااااااااااااااااا

  8. #28
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par lqayoub Voir le message
    Merci Merci Merci Merci Merci
    et en arabe
    شكراااااااااااااااااااااااااااااااااااا
    Là c'est moi qui te remercie!

  9. #29
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 19
    Points : 18
    Points
    18
    Par défaut
    j'ai rien a dire !
    Tu peux etre mon prof s'il te plait !

  10. #30
    Invité
    Invité(e)
    Par défaut
    Pourquoi ton prof ne t'as jamais parlé de ça?

    De toutes les façons il faudra bien aborder comme adapter le code à ton UserForm, pour passer les valeur au sub Ajouter

  11. #31
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 19
    Points : 18
    Points
    18
    Par défaut
    Comment inseret dans une datagridviewn sans enregister a la base de donnée ?
    s'il te plait : )

  12. #32
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Je suis dans le transport en commun, mais en attendant voilà un lien où je fais cette opération!

    C'est du sal serveur mais c'est la même idée!


    http://www.developpez.net/forums/d15...t/#post8598143

  13. #33
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 19
    Points : 18
    Points
    18
    Par défaut
    Salut M. rdurupt
    J'espere que tu vas bien !
    je realise une application de gestion sportive
    et je veux ajouter une image pour un adherent !
    mais je trouve toujours une erreur !
    volia code button Ajouter:
    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
     Dim savinto As New OleDb.OleDbCommand
            Dim dtadapter As New OleDbDataAdapter(sqlAdherent, maconection)
            ' Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
            ' Dim breader As New BinaryReader(fsreader)
            ' Dim imgbuffer(fsreader.Length) As Byte
            ' breader.Read(imgbuffer, 0, fsreader.Length)
            ' fsreader.Close()
            savinto.Connection = maconection
            savinto.CommandType = CommandType.Text
            savinto.CommandText = "insert into T_Adherent(Code_Adherent,Nom_Adher,Prenom_adher,Adresse_Adher,Date_naissance,CIN,Num_pasport,Tél_Adher,Profession_Adher,Nationlité_Adher,Civilité_Adher,Niveau_detude,Taill_Adher,Poid_Adher,Date_inscription,Image_Adher,Ceinture_Adher,Grade_Adher,Sexe_Adher,Type_Adher,Categorie,Entraineur,heurDentrainement,gruuup,jour_Dentrainement)" & " values('" & txt_Adherent.Text & "','" & txt_Nom.Text & "','" & txt_Prenom.Text & "','" & txt_Adresse.Text & "','" & Date_naissance.Value.ToString("dd/MM/yyy") & "','" & txt_CIN.Text & "','" & txt_Passport.Text & "','" & txt_Telephone.Text & "','" & txt_Profession.Text & "','" & txt_Nationaliter.Text & "','" & civilité & "','" & txt_NiveauEtude.Text & "','" & txt_Taille.Text & "','" & txt_Poid.Text & "','" & date_Inscription.Value.ToString("dd/MM/yyy") & "','" & str & "','" & cmb_Ceinture.Text & "','" & cmb_Grade.Text & "','" & sexe & "','" & cmb_Type.Text & "','" & cmb_Categorie.Text & "','" & txt_Entrainneur.Text & "','" & txt_heurDentrainement.Text & "','" & txt_Groop.Text & "','" & txt_jourDentrainemet.Text & "')"
            maconection.Open()
            savinto.ExecuteNonQuery()
            dtset.Clear()
            dtadapter.Fill(dtset, "T_Adherent")
            maconection.Close()
            MsgBox("votre nouveau enregistrement et bien enregistrer")
    et un autre problem quand la recherchen je ne trouve pas l'image !
    code button rechercher
    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
      Dim rech As String = ""
            rech = InputBox("entrer le code d'Adherent rechercher", "programme de recherche")
            Dim sql_rech As String = "select * from T_Adherent where Code_Adherent LIKE '" & Val(rech) & "'"
            If maconection.State() Then maconection.Close()
            maconection.Open()
            Dim cmd As New OleDbCommand(sql_rech, maconection)
            Dim dtred = cmd.ExecuteReader
            Dim cv, sx As String
            If dtred.Read = True Then
                txt_Adherent.Text = dtred.Item(0).ToString
                txt_Nom.Text = dtred.Item(1).ToString
                txt_Prenom.Text = dtred.Item(2).ToString
                txt_Adresse.Text = dtred.Item(3).ToString
                Date_naissance.Text = dtred.Item(4).ToString
                txt_CIN.Text = dtred.Item(5).ToString
                txt_Passport.Text = dtred.Item(6).ToString
                txt_Telephone.Text = dtred.Item(7).ToString
                txt_Profession.Text = dtred.Item(8).ToString
                txt_Nationaliter.Text = dtred.Item(9).ToString
                cv = dtred.Item(10).ToString.Trim
                If cv = "M." Then
                    Rad_M.Checked = True
                End If
                If cv = "Mlle" Then
                    Rad_Mlle.Checked = True
                End If
                If cv = "Mmd" Then
                    Rad_Mmd.Checked = True
                End If
                txt_NiveauEtude.Text = dtred.Item(11).ToString
                txt_Taille.Text = dtred.Item(12).ToString
                txt_Poid.Text = dtred.Item(13).ToString
                date_Inscription.Text = dtred.Item(14).ToString
                Photos.ImageLocation = dtred.Item(15).ToString
                cmb_Ceinture.Text = dtred.Item(16).ToString
                cmb_Grade.Text = dtred.Item(17).ToString
                sx = dtred.Item(18).ToString.Trim
                If sx = "Masculin" Then
                    Rad_Masculin.Checked = True
                ElseIf sx = "feminin" Then
                    Rad_Feminin.Checked = True
                End If
                cmb_Type.Text = dtred.Item(19).ToString
                cmb_Categorie.Text = dtred.Item(20).ToString
                txt_Entrainneur.Text = dtred.Item(21).ToString
                txt_heurDentrainement.Text = dtred.Item(22).ToString
                txt_Groop.Text = dtred.Item(23).ToString
                txt_jourDentrainemet.Text = dtred.Item(24).ToString
     
                maconection.Close()
            Else
                maconection.Close()
                MessageBox.Show("ce Adherent est introuvable", "erreur de rcherche", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            End If
    Et Merciii !

Discussions similaires

  1. Pb lecture base Access
    Par cjacquel dans le forum Access
    Réponses: 2
    Dernier message: 17/01/2012, 17h00
  2. IE Mozilla, problème lecture base Access
    Par letel dans le forum ASP.NET
    Réponses: 0
    Dernier message: 05/02/2009, 21h11
  3. Pb Lecture Base Access Vista -> XP
    Par cjacquel dans le forum Sécurité
    Réponses: 2
    Dernier message: 03/03/2008, 17h41
  4. Lenteur lors de la lecture d'une base Access
    Par Lio590 dans le forum Bases de données
    Réponses: 6
    Dernier message: 16/11/2005, 12h24
  5. Réponses: 3
    Dernier message: 30/06/2004, 11h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo