'Importations des Bibliothèque Imports System.Data 'Pour la BD Imports System.Data.SqlClient 'Pour la SQL pour la BD Imports System.Configuration 'Configuration Imports System.Data.Common Public Class ClassConnexionBase 'Les Variables de connexion Dim Cn As SqlConnection 'Objet de connexion Dim com As SqlCommand 'Reçoit (execution)ls rêquetes SQL Private _chaineConnection As String 'Reçoit la chaine de connexion Private _sql As String 'reçoit les variables requetes en strings Private _rd As SqlDataReader 'Retourne la var private Public Property rd() As SqlDataReader Get Return _rd End Get Set(ByVal value As SqlDataReader) _rd = value End Set End Property Public Property SQL() As String Get Return _sql End Get Set(ByVal value As String) _sql = value End Set End Property Public Property chaineConnection() As String Get Return _chaineConnection End Get Set(ByVal value As String) _chaineConnection = value End Set End Property Public ReadOnly Property connexion() As SqlConnection 'Read octroie le droit de lecture pas de modification Get Return Cn End Get End Property Public Sub initialise() Me.Cn = Nothing Me.com = Nothing End Sub Public Sub ouvrirconnexion(ByVal chaineConnection As String) Try If Me.Cn Is Nothing Then 'Me=la var actuelle If Me._chaineConnection = String.Empty Then Throw New Exception("Indiquer la chaine de connexion avant de tenter une ouverture") End If End If Me.Cn = New SqlConnection(Me._chaineConnection) Me.Cn.Open() Catch ex As Exception Throw ex End Try End Sub Public Sub selectionsql(ByVal requette As String) 'Call ouvrirconnexion(chaineConnection) com = New SqlCommand com.CommandText = SQL Try com.Connection = Me.Cn _rd = com.ExecuteReader() Catch ex As Exception MessageBox.Show(ex.Message) End Try 'While rd.Read() 'num = rd("numcon") 'nom = rd("nomconn") 'rd.GetString(2) 'rd.GetString(3) 'rd.GetDateTime(4) 'End While End Sub Public Sub insertionsql(ByVal SQL As String, ByVal photo As Byte()) Try com = New SqlCommand com.CommandText = SQL com.Parameters.Add("@image", SqlDbType.VarBinary).Value = photo com.Connection = Me.Cn If com.ExecuteNonQuery() Then MsgBox("Opération reussie") Else MsgBox("Opération échouée") End If Catch ex As SqlException MessageBox.Show(ex.Message) End Try End Sub Public Sub insertionsql(ByVal SQL As String) Try com = New SqlCommand com.CommandText = SQL com.Connection = Me.Cn If com.ExecuteNonQuery() Then MsgBox("Résultat,,Opération reussie") Else MsgBox("Opération échouée,,Résultat") End If Catch ex As SqlException MessageBox.Show(ex.Message) End Try End Sub Public Sub update(ByVal SQL As String, ByVal photo As Byte()) Try com = New SqlCommand com.CommandText = SQL com.Parameters.Add("@image", SqlDbType.VarBinary).Value = photo com.Connection = Me.Cn If com.ExecuteNonQuery() Then MsgBox("Mise à jour reussie") Else MsgBox("Mise à jour échouée") End If Catch ex As SqlException MessageBox.Show(ex.Message) End Try End Sub Public Sub update(ByVal SQL As String) Try com = New SqlCommand com.CommandText = SQL com.Connection = Me.Cn If com.ExecuteNonQuery() Then MsgBox("Mise jour réussie") Else MsgBox("Mise jour échouée") End If Catch ex As SqlException MessageBox.Show(ex.Message) End Try End Sub Public Sub delete(ByVal SQL As String) Try com = New SqlCommand com.CommandText = SQL com.Connection = Me.Cn If com.ExecuteNonQuery() Then MsgBox("La ligne selectionnée a été supprimée") Else MsgBox("Echec de suppression") End If Catch ex As SqlException MessageBox.Show(ex.Message) End Try End Sub End Class