Test creation base Access

thomasaurelien Messages postés 71 Date d'inscription jeudi 7 juillet 2011 Statut Membre Dernière intervention 27 novembre 2017 - 10 août 2011 à 11:44
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 - 10 août 2011 à 16:34
Bonjour, voila je suis entrain de créer un petit programme dont la base se créer au 1er lancement de l'application mais après avoir recherché sur internet je n'ai pas trouvé quelque chose de concret.
J'ai quand même réussi a écrire ce code avec lequel j'ai un peu de mal
Si quelqu'un connaît un lien pour des explications merci d'avance .
        If (("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\Film.accdb") Is Nothing) Then
            MsgBox("Base déja créer")
        Else
            db = db.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\Film.accdb")
            MsgBox("base créer")
        End If

7 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
10 août 2011 à 12:56
Bonjour,
Voici une façon de créer une base access:
'Il faut d'abord ajouter la référence ADOX (menu "Projet/Références/COM..." puis sélectionner "Microsoft ADO Ext. 2.8 for DDL and Security").

Public Class Form1
    Dim cat As New ADOX.Catalog

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If (("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\MyDataBase.mdb") Is Nothing) Then
            Else
                cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\MyDataBase.mdb")
                MsgBox("Base créer")
            End If
        Catch
        End Try
    End Sub
End Class



@+Le Pivert
0
thomasaurelien Messages postés 71 Date d'inscription jeudi 7 juillet 2011 Statut Membre Dernière intervention 27 novembre 2017
10 août 2011 à 13:24
Impécable le Pivert merci bien
0
thomasaurelien Messages postés 71 Date d'inscription jeudi 7 juillet 2011 Statut Membre Dernière intervention 27 novembre 2017
10 août 2011 à 14:37
Euh j'ai rep un peu vite pour la création de la base sa marche mais à chaque fois que je lance l'appli ça m'affiche les conditions se trouvant dans le else alors que c'est cencé affiché "Base existante"

        Try
            If (("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\Film.accdb") Is Nothing) Then
                MsgBox("Base existante")
            Else
                MsgBox("Base inexistante")
                MsgBox("Création de la base de données : FILM", MessageBoxIcon.Information, MessageBoxButtons.OK)
                db.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\Film.accdb")
                MsgBox("Base créer")
            End If

        Catch

        End Try
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
10 août 2011 à 16:26
Je t'ai répondu rapidement. Tu peux mettre ceci pour afficher un message quand la base existe déjà:


'Il faut d'abord ajouter une référence à ADOX (menu "Projet/Références/COM..." puis sélectionner "Microsoft ADO Ext. 2.8 for DDL and Security").

Public Class Form1
    Dim cat As New ADOX.Catalog
    Dim existe As Boolean

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If (("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\MyDataBase.mdb") Is Nothing) Then
                existe = False
            Else
                cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\MyDataBase.mdb")
                MsgBox("Base créer")
            End If
        Catch
            If existe = False Then
                MsgBox("Base déjà créer")
            End If
        End Try

    End Sub
End Class



@+Le Pivert
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
10 août 2011 à 16:30
C'est plus logique comme cela en mettant True


'Il faut d'abord ajouter une référence à ADOX (menu "Projet/Références/COM..." puis sélectionner "Microsoft ADO Ext. 2.8 for DDL and Security").

Public Class Form1
    Dim cat As New ADOX.Catalog
    Dim existe As Boolean

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If (("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\MyDataBase.mdb") Is Nothing) Then
                existe = True
            Else
                cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\MyDataBase.mdb")
                MsgBox("Base créer")
            End If
        Catch
            If existe = True Then
                MsgBox("Base déjà créer")
            End If
        End Try

    End Sub
End Class
0
thomasaurelien Messages postés 71 Date d'inscription jeudi 7 juillet 2011 Statut Membre Dernière intervention 27 novembre 2017
10 août 2011 à 16:31
Voila finallement j'ai trouvé comment créer la base si celle-ci n'est pas créer (utile pour la creation d'une base au 1er lancement d'une appli)

        If System.IO.File.Exists("film.accdb") Then
            MsgBox("Base existante")
        Else
            MsgBox("Base inexistante")
            MsgBox("Création de la base de données : FILM", MessageBoxIcon.Information, MessageBoxButtons.OK)
            db.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\Film.accdb")
            MsgBox("Base créer")
        End If
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
10 août 2011 à 16:34
Autant pour moi, cela ne marche pas avec True, c'est donc le 1er exemple qu'il faut prendre avec False

Le Pivert
0
Rejoignez-nous