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 :

Insert to encore [Débutant]


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Service public

    Informations forums :
    Inscription : Février 2012
    Messages : 29
    Par défaut Insert to encore
    Bonjour

    Je reviens avec une question éternelle mais qui persiste.

    Je crée une nouvelle ligne dans ma base de données et INSERT TO est méchant. Il m'indique que j'ai une erreur de synthaxe (facile...).

    Alors j'ai éclusé les forums, vérifié le nom de mes champs Access, rien.

    Je ne passe pratiquement pas par SQL (sauf pour le select initial), je n'ai pas paramétré le dataset ni stocké quoi que ce soit. Je n'utilise que NewRow et Add.

    La procédure incriminée est NouvelleFiche, mais je vous mets le reste.

    Si cela inspire...

    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
     
    Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim ajd = System.DateTime.Now
            'Dim configpath As String
            'Dim mypath As String
     
            configpath = Application.StartupPath & "\Path.txt"
            Try
                If File.Exists(configpath) = False Then
                    OpenFileDialog1.FileName = "Path.txt"
                    OpenFileDialog1.DefaultExt = ".txt"
                    If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                        OpenFileDialog1.RestoreDirectory = False
                        OpenFileDialog1.InitialDirectory = "..\"
                        configpath = OpenFileDialog1.FileName
                    Else : Exit Sub
                    End If
                End If
                mypath = File.ReadAllText(configpath)
     
                If mypath = "" Then
                    OpenFileDialog1.FileName = "db1.mdb"
                    OpenFileDialog1.DefaultExt = ".mdb"
                    If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                        OpenFileDialog1.RestoreDirectory = True
                        mypath = OpenFileDialog1.FileName
                        File.WriteAllText(configpath, mypath)
                    Else : Exit Sub
                    End If
                End If
     
     
            Catch ex As Exception
     
     
            End Try
     
            strConn = "Provider=Microsoft.jet.OLEDB.4.0;Data Source= " & mypath & ";"
            objetConnection = New OleDbConnection()
            objetConnection.ConnectionString = strConn
            objetConnection.Open()
            Requetes()
            objetDataAdapter.Dispose()
            objetConnection.Close()
     
            Dim res = From elt In tablectrl
                     Where elt.Field(Of String)("Début CJ") < ajd And elt.Field(Of String)("Fin") > ajd
                     Select elt
     
            For Each p In res
                ListBox1.Items.Add(p("Nom").ToString & " " & p("Prénom").ToString)
            Next
    end sub
    Public Sub nouvelle_fiche()
     
            If IsDate(Contacts_Form.Deb_DateTimePicker.Text) = False Then
                MsgBox("Saisissez une date de début de CJ valide")
                Exit Sub
            End If
     
            If IsDate(Contacts_Form.Fin_DateTimePicker.Text) = False Then
                MsgBox("Saisissez une date de fin de CJ valide")
                Exit Sub
            End If
     
            If IsNumeric(Contacts_Form.Freq_TextBox.Text) = False Then
                MsgBox("Saisissez une fréquence de côntrôle valide")
                Exit Sub
            End If
     
            Dim maLigne As DataRow = monDataset.Tables("Fiche").NewRow
     
            maLigne("Nom") = Contacts_Form.Nom_TextBox.Text
            maLigne("Date_de_naissance") = CType(Contacts_Form.DateN_TextBox.Text, Date)
            maLigne("Prénom") = Contacts_Form.Prenom_TextBox.Text
            maLigne("Adresse") = Contacts_Form.Adresse_TextBox.Text
            maLigne("Ville") = Contacts_Form.Ville_TextBox.Text
            maLigne("Code postal") = Contacts_Form.CP_TextBox.Text
            maLigne("Début CJ") = CType(Contacts_Form.Deb_DateTimePicker.Text, Date)
            maLigne("Fin") = CType(Contacts_Form.Fin_DateTimePicker.Text, Date)
            maLigne("Fréquence") = CType(Contacts_Form.Freq_TextBox.Text, Double)
            maLigne("Motif suivi") = Contacts_Form.Motif_TextBox.Text
            maLigne("Personne référente") = Contacts_Form.Ref_TextBox.Text
            maLigne("Mail") = Contacts_Form.Mail_TextBox.Text
            maLigne("Téléphone") = Contacts_Form.Tel_TextBox.Text
     
            monDataset.Tables("Fiche").Rows.Add(maLigne)
     
            'Try
            objetCommand = New OleDbCommand(strSql)
            objetCommand.Connection() = objetConnection
            objetDataAdapter.SelectCommand = objetCommand
            objetCommandBuilder = New OleDb.OleDbCommandBuilder(objetDataAdapter)
            objetDataAdapter.InsertCommand = objetCommandBuilder.GetInsertCommand
            objetDataAdapter.Update(monDataset, "Fiche")
            monDataset.Clear()
            objetDataAdapter.Fill(monDataset, "Fiche")
            tableFiches = monDataset.Tables("Fiche")
            'Catch ex As Exception
            'End Try
     
        End Sub
        Public Sub Requetes()
     
            strSql = "SELECT * FROM Fiche"
            objetCommand = New OleDbCommand(strSql)
            objetDataAdapter = New OleDbDataAdapter(objetCommand)
            objetCommand.Connection() = objetConnection
            objetDataAdapter.Fill(monDataset, "Fiche")
            tableFiches = monDataset.Tables("Fiche")
     
            strSql2 = "SELECT * FROM Suivi"
            objetCommand = New OleDbCommand(strSql2)
            objetDataAdapter = New OleDbDataAdapter(objetCommand)
            objetCommand.Connection() = objetConnection
            objetDataAdapter.Fill(monDataset, "Suivi")
            tableFiches = monDataset.Tables("Suivi")
     
        End Sub

  2. #2
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Service public

    Informations forums :
    Inscription : Février 2012
    Messages : 29
    Par défaut
    Précision : le code est stocké dans un module. J'ai peut-être des problèmes de références.

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Service public

    Informations forums :
    Inscription : Février 2012
    Messages : 29
    Par défaut
    Espaces dans les noms de colonne sous Access qui ne sont pas supportés par l'OLEDBCommandBuilder.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. UPDATE ou INSERT si n'existe pas encore
    Par Natim87 dans le forum Langage SQL
    Réponses: 9
    Dernier message: 17/08/2009, 14h13
  2. Programmer encore en VB 6 c'est pas bien ? Pourquoi ?
    Par Nektanebos dans le forum Débats sur le développement - Le Best Of
    Réponses: 85
    Dernier message: 10/03/2009, 14h43
  3. Encore une insertion de ligne
    Par dreloman dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 05/07/2008, 21h52
  4. [multiset..encore!]Vérifier une insertion
    Par joejoe230 dans le forum SL & STL
    Réponses: 1
    Dernier message: 21/10/2007, 21h15
  5. Réponses: 4
    Dernier message: 28/09/2002, 00h00

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