If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Chants.mdb") Then con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =" & My.Application.Info.DirectoryPath & "\Chants.mdb" Else MsgBox("Connection à chants.mdb impossible !" & Chr(13) & "Fichier introuvable à l'emplacement:" & Chr(13) & My.Application.Info.DirectoryPath, MsgBoxStyle.Critical) Me.Close() End If Dim sql_chant As String Dim sql_paroles As String Dim sql_répertoires As String sql_chant = "SELECT * FROM T_Chant" cmd = New OleDbCommand(sql_chant, con) cmd.Connection.Open() da_chant.SelectCommand = cmd da_chant.FillSchema(ds, SchemaType.Source, "T_chant") da_chant.MissingSchemaAction = MissingSchemaAction.AddWithKey da_chant.Fill(ds, "T_Chant") cmd.Connection.Close() sql_paroles = "SELECT * FROM T_Paroles" cmd = New OleDbCommand(sql_paroles, con) cmd.Connection.Open() da_paroles.SelectCommand = cmd da_paroles.FillSchema(ds, SchemaType.Source, "T_chant") da_paroles.MissingSchemaAction = MissingSchemaAction.AddWithKey da_paroles.Fill(ds, "T_Paroles") cmd.Connection.Close() sql_répertoires = "SELECT * FROM T_Répertoires" cmd = New OleDbCommand(sql_répertoires, con) cmd.Connection.Open() da_repertoires.SelectCommand = cmd da_repertoires.FillSchema(ds, SchemaType.Source, "T_Répertoires") da_repertoires.MissingSchemaAction = MissingSchemaAction.AddWithKey da_repertoires.Fill(ds, "T_Répertoires") cmd.Connection.Close() Dim R_ChantParoles, R_ChantRépertoires As DataRelation Dim ChantRef_Column, ParolesNum_Column, RépertoireRef_Column, ChantRépertoire_Column As DataColumn ChantRef_Column = ds.Tables("T_chant").Columns("ref") ParolesNum_Column = ds.Tables("T_Paroles").Columns("N_Chant") ChantRépertoire_Column = ds.Tables("T_Chant").Columns("Répertoire") RépertoireRef_Column = ds.Tables("T_Répertoires").Columns("N°") R_ChantParoles = New DataRelation("R_ChantParoles", ChantRef_Column, ParolesNum_Column) R_ChantRépertoires = New DataRelation("R_ChantRépertoires", RépertoireRef_Column, ChantRépertoire_Column) ds.Relations.Add(R_ChantParoles) ds.Relations.Add(R_ChantRépertoires) R_ChantRépertoires.ChildKeyConstraint.DeleteRule = Rule.SetNull R_ChantRépertoires.ChildKeyConstraint.UpdateRule = Rule.Cascade Répertoires_BindingSource.DataSource = ds Répertoires_BindingSource.DataMember = "T_répertoires" Chant_BindingSource.DataSource = ds Chant_BindingSource.DataMember = "T_chant" Paroles_BindingSource.DataSource = Chant_BindingSource Paroles_BindingSource.DataMember = "R_ChantParoles" ListBox_Chants.DataSource = Chant_BindingSource ListBox_Chants.DisplayMember = "Titre" TextBox_Titre.DataBindings.Add(New Binding("text", Chant_BindingSource, "Titre")) TextBox_AuteurMusique.DataBindings.Add(New Binding("text", Chant_BindingSource, "Auteur_Musique")) TextBox_AuteurParoles.DataBindings.Add(New Binding("text", Chant_BindingSource, "Auteur_Paroles")) TextBox_Code.DataBindings.Add(New Binding("text", Chant_BindingSource, "Code")) TextBox_Remarques.DataBindings.Add(New Binding("text", Chant_BindingSource, "Remarques")) TextBox1.DataBindings.Add(New Binding("Text", Chant_BindingSource, "Répertoire")) ComboBox_Répertoire.DataSource = Répertoires_BindingSource ComboBox_Répertoire.DisplayMember = "Répertoire" ComboBox_Repertoires.DataSource = ds.Tables("T_répertoires") ComboBox_Repertoires.DisplayMember = "Répertoire" DataRepeater_Paroles.VirtualMode = True BindingNavigator_Paroles.BindingSource = Paroles_BindingSource DataRepeater_Paroles.DataSource = Paroles_BindingSource TextBox_Paroles.DataBindings.Add(New Binding("text", Paroles_BindingSource, "Paroles")) ComboBox_Paroles.DataSource = Paroles_BindingSource ComboBox_Paroles.DisplayMember = "type"
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub ToolStripButton_RépertoireAjouter_Click(sender As Object, e As EventArgs) Handles ToolStripButton_RépertoireAjouter.Click Try Dim répertoire As String = InputBox("Nom du répertoire:", "Ajouter un nouveau répertoire").ToString If répertoire <> "" Then Dim row As DataRow = ds.Tables("T_Répertoires").NewRow row("Répertoire") = répertoire ds.Tables("T_répertoires").Rows.Add(row) Dim cb_repertoire As New OleDbCommandBuilder(da_repertoires) da_repertoires.Update(ds, "T_répertoires") End If Catch ex As Exception MsgBox(ex.ToString) End Try
Dim titre As String = InputBox("Titre du chant:", "Titre") If titre = "" Then Mode_Lecture() ElseIf Chant_BindingSource.Find("titre", titre) >= 0 Then Select Case MsgBox("Le chant '" & titre & "' existe déjà !" & vbNewLine & "Voulez-vous le modifier?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Nouveau chant") Case MsgBoxResult.Yes Chant_BindingSource.Position = Chant_BindingSource.Find("Titre", titre) ToolStripButton_Modifier.PerformClick() Case MsgBoxResult.No Mode_Lecture() End Select Else Chant_BindingSource.AddNew() TextBox_Titre.Text = titre Chant_BindingSource.EndEdit() Dim cb_chant As New OleDbCommandBuilder(da_chant) da_chant.Update(ds, "T_chant") ds.Clear() da_chant.Fill(ds, "T_chant") da_paroles.Fill(ds, "T_paroles") da_repertoires.Fill(ds, "T_répertoires") Chant_BindingSource.MoveLast() End If