L'exception OleDbException n'a pas été gérée
http://img175.imageshack.us/img175/8895/problemk.jpg
Code:
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
|
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
' Déclaration Objet Connexion
Dim ObjetConnection As OleDbConnection
' Déclaration Objet Commande
Dim ObjetCommand As OleDbCommand
' Déclaration Objet DataAdapter
Dim ObjetDataAdapter As OleDbDataAdapter
' Déclaration Objet DataSet
Dim ObjetDataSet As New DataSet() 'Attention au New
'String contenant la 'Requête SQL'
Dim strSql As String
' Déclaration Objet DataTable
Dim ObjetDataTable As DataTable
' Déclaration Objet DataRow (ligne)
Dim ObjetDataRow As DataRow
'Numéro de la ligne en cours
Dim RowNumber As Integer 'Numéro de l'enregistrement courant
'Paramêtres de connexion à la DB
Dim strConn As String
'Pour recompiler les données modifiées avant de les remettre dans le
'"DataAdapter"
Dim ObjetCommandBuilder As OleDbCommandBuilder
Sub connection()
'Initialisation de la chaîne de paramètres pour la connexion
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & "C:\Documents and Settings\kazkoz\Mes documents\Visual Studio 2008\Projects\dasok\bd1.mdb"
'Initialisation de la chaîne contenant l'instruction SQL
strSql = "SELECT * FROM TS ORDER BY NOM"
'Instanciation d'un Objet Connexion
ObjetConnection = New OleDbConnection()
'Donner à la propriété ConnectionString les paramètres de connexion
ObjetConnection.ConnectionString = strConn
'Ouvrir la connexion
ObjetConnection.Open()
'Instancier un objet Commande
ObjetCommand = New OleDbCommand(strSql)
'Instancier un objet Adapter
ObjetDataAdapter = New OleDbDataAdapter(ObjetCommand)
'initialiser l'objet Command
ObjetCommand.Connection() = ObjetConnection
'Avec l'aide de la propriété Fill du DataAdapter charger le DataSet
ObjetDataAdapter.Fill(ObjetDataSet, "TS")
'Mettre dans un Objet DataTable une table du DataSet
ObjetDataTable = ObjetDataSet.Tables("TS")
End Sub
'---------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connection()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
' Extraire l'enregistrement courant
ObjetDataRow = ObjetDataSet.Tables("TS").Rows(RowNumber)
'Modifier les valeurs des champs en récupérant le contenu des TextBox
ObjetDataRow("Matriculation") = TextBox61.Text
ObjetDataRow("Prenom") = TextBox62.Text
ObjetDataRow("Nom") = TextBox63.Text
ObjetDataRow("DATE-N") = TextBox64.Text
ObjetDataRow("LIEU-N") = TextBox65.Text
ObjetDataRow("ADR") = TextBox66.Text
ObjetDataRow("filial") = TextBox67.Text
ObjetDataRow("DATE-E") = TextBox68.Text
'Pour modifier les valeurs changées dans le DataAdapter
ObjetCommandBuilder = New OleDbCommandBuilder(ObjetDataAdapter)
'Mise à jour
'Try
ObjetDataAdapter.Update(ObjetDataSet, "TS")
'Catch
'MsgBox("ERROR................")
' End Try
'ObjetDataAdapter.Update(ObjetDataSet, "TS")
'On vide le DataSet et on le 'recharge' de nouveau.
ObjetDataSet.Clear()
ObjetDataAdapter.Fill(ObjetDataSet, "TS")
ObjetDataTable = ObjetDataSet.Tables("TS")
End Sub |