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
| Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class form3
Dim mycnn As SqlConnection = New SqlConnection
Private Sub form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mycnn.ConnectionString = "Data source=(local); database= Facturation; Integrated security=true"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles Button4.Click
Try
If (TextBox1.Text) = "" Or (TextBox2.Text) = "" Then
MsgBox("Vous devez entrer tous les paramètres")
Else
Call InsertU()
End If
Catch ex As Exception
End Try
End Sub
Sub InsertU()
Try
Dim mycmd As SqlCommand = New SqlCommand
mycmd.Connection = mycnn
mycmd.CommandType = CommandType.StoredProcedure
mycmd.CommandText = "dbo.Inserer"
Call Ajouts_Parametres(mycmd, "@userts", DbType.String, TextBox1.Text)
Call Ajouts_Parametres(mycmd, "@login", DbType.String, TextBox2.Text)
If mycnn.State = ConnectionState.Closed Then mycnn.Open()
mycmd.ExecuteNonQuery()
MsgBox("Opération d'ajout terminée avec succès !", MsgBoxStyle.Information,
"Résultat")
Catch obj As Exception
If mycnn.State = ConnectionState.Open Then mycnn.Close()
MsgBox(obj.Message)
End Try
End Sub
Sub Ajouts_Parametres(ByVal paramSQLCommand As SqlCommand, ByVal paramNomParametre As String, ByVal paramTypeValeur As DbType, ByVal paramValeur As Object)
Dim varSQLParam As New SqlParameter(paramNomParametre, paramTypeValeur)
Dim paramSQL As SqlParameter = New SqlParameter
varSQLParam.Direction = ParameterDirection.Input
varSQLParam.Value = paramValeur
paramSQLCommand.Parameters.Add(varSQLParam)
End sub
End class |
Partager