- Imports System.Data.OleDb
- Public Class clsGestionSQL
-
- Public myConnection As OleDbConnection
- Private myDataReader As OleDbDataReader
-
- ' Ouvrir la connexion
- Public Sub openConnection(ByVal path As String)
- myConnection = New OleDbConnection
- myConnection.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & path
- ' Ouvre la connexion
- myConnection.Open()
- End Sub
-
- ' Ferme la connexion
- Public Sub closeConnection()
- myConnection.Close()
- End Sub
-
- ' Rempli un dataSet pour le retourner
- Public Function fillDataSet(ByVal pCommand As String) As Data.DataSet
- Dim dataAdapter As New OleDbDataAdapter(pCommand, myConnection)
- Dim dataSet As New Data.DataSet
- dataAdapter.Fill(dataSet)
- Return dataSet
- End Function
-
- ' Rempli le dataReader dépendant de la commande
- Public Function executeQuery(ByVal pCommand As String) As OleDbDataReader
- Dim maCommande As OleDbCommand
-
- maCommande = New OleDbCommand(pCommand, myConnection)
- ' Exécute la commande et l'affecte dans un dataReader
- myDataReader = maCommande.ExecuteReader()
- Return myDataReader
- End Function
-
- Public Function executeNonQuery(ByVal command As String) As Integer
- Dim sqlCommand As New OleDbCommand(command, myConnection)
- Dim integerToReturn As Integer
-
- integerToReturn = sqlCommand.ExecuteNonQuery()
-
- Return integerToReturn
- End Function
-
- ' Fonction pour crypter en MD5 le mot de passe
- Public Function md5Crypt(ByVal pText As String) As String
- Return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pText, "md5")
- End Function
-
- ' Remplace les caractères spéciaux
- Public Function replaceCarac(ByVal ptext As String) As String
- Dim text As String
- text = Replace(ptext, "'", "%1")
- text = Replace(text, "&", "%2")
- text = Replace(text, "\", "%3")
- text = Replace(text, "#", "%4")
- text = Replace(text, "<", "<")
- text = Replace(text, ">", ">")
- Return text
- End Function
-
- ' "Déremplace" les caractères spéciaux
- Public Function deReplaceCarac(ByVal ptext As String) As String
- Dim text As String
- text = Replace(ptext, "%1", "'")
- text = Replace(text, "%2", "&")
- text = Replace(text, "%3", "\")
- text = Replace(text, "%4", "#")
- Return text
- End Function
-
- End Class
Imports System.Data.OleDb
Public Class clsGestionSQL
Public myConnection As OleDbConnection
Private myDataReader As OleDbDataReader
' Ouvrir la connexion
Public Sub openConnection(ByVal path As String)
myConnection = New OleDbConnection
myConnection.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & path
' Ouvre la connexion
myConnection.Open()
End Sub
' Ferme la connexion
Public Sub closeConnection()
myConnection.Close()
End Sub
' Rempli un dataSet pour le retourner
Public Function fillDataSet(ByVal pCommand As String) As Data.DataSet
Dim dataAdapter As New OleDbDataAdapter(pCommand, myConnection)
Dim dataSet As New Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
' Rempli le dataReader dépendant de la commande
Public Function executeQuery(ByVal pCommand As String) As OleDbDataReader
Dim maCommande As OleDbCommand
maCommande = New OleDbCommand(pCommand, myConnection)
' Exécute la commande et l'affecte dans un dataReader
myDataReader = maCommande.ExecuteReader()
Return myDataReader
End Function
Public Function executeNonQuery(ByVal command As String) As Integer
Dim sqlCommand As New OleDbCommand(command, myConnection)
Dim integerToReturn As Integer
integerToReturn = sqlCommand.ExecuteNonQuery()
Return integerToReturn
End Function
' Fonction pour crypter en MD5 le mot de passe
Public Function md5Crypt(ByVal pText As String) As String
Return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pText, "md5")
End Function
' Remplace les caractères spéciaux
Public Function replaceCarac(ByVal ptext As String) As String
Dim text As String
text = Replace(ptext, "'", "%1")
text = Replace(text, "&", "%2")
text = Replace(text, "\", "%3")
text = Replace(text, "#", "%4")
text = Replace(text, "<", "<")
text = Replace(text, ">", ">")
Return text
End Function
' "Déremplace" les caractères spéciaux
Public Function deReplaceCarac(ByVal ptext As String) As String
Dim text As String
text = Replace(ptext, "%1", "'")
text = Replace(text, "%2", "&")
text = Replace(text, "%3", "\")
text = Replace(text, "%4", "#")
Return text
End Function
End Class