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
|
Public Class DAL
#Region "Constructeurs"
Sub New()
End Sub
#End Region
#Region "Méthodes DAL"
'Insert d'un nouvel User dans la base
Public Sub DALAjouter(ByVal NewUser As User)
'Déclaration chaine de connexion & requête SQL paramètrée
Dim strConnexion As String = "Data Source=xxxxx;Initial Catalog=Formulaire;Integrated Security=SSPI;"
Dim strRequete As String = "INSERT INTO T_USER (ID, NOM, PRENOM, AGE, VILLE) VALUES (@ID, @NOM, @PRENOM, @AGE, @VILLE)"
'Instanciation des objets Connexion et Commandes
Dim Connexion As SqlConnection = New SqlConnection(strConnexion)
Dim Command As SqlCommand = New SqlCommand(strRequete, Connexion)
'Ajout des paramètres à Command
With Command.Parameters
.Add("@ID", SqlDbType.Int, 4)
.Add("@NOM", SqlDbType.NChar, 10)
.Add("@PRENOM", SqlDbType.NChar, 10)
.Add("@AGE", SqlDbType.Int, 4)
.Add("@VILLE", SqlDbType.NChar, 10)
End With
With Command
.Parameters("@ID").Value = NewUser.ID
.Parameters("@NOM").Value = NewUser.NOM
.Parameters("@PRENOM").Value = NewUser.PRENOM
.Parameters("@AGE").Value = NewUser.AGE
.Parameters("@VILLE").Value = NewUser.VILLE
End With
'Connexion et éxécution
Connexion.Open()
Command.ExecuteNonQuery()
Connexion.Close()
End Sub |
Partager