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
| Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'-------------------------------------
' Variables declaration
'-------------------------------------
Dim objCommand As SqlCommand
Dim objParam As SqlParameter
Dim dt_KeywordsID As DataTable = New DataTable("produit")
Dim dtc_KeywordsID As DataColumn
Dim myConnection As SqlConnection = New SqlConnection("data source=UC033\DEV;integrated security=SSPI;initial catalog=BUDGET2")
If Not String.IsNullOrWhiteSpace(nom.Text) Then
'Traitement
'-------------------------------------
' Create a connection to SQL Server
'-------------------------------------
objCommand = New SqlCommand("dbo.spd_produit_insert", myConnection)
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Connection.Open()
'-------------------------------------
' Create parameters for sp
'-------------------------------------
objParam = objCommand.Parameters.Add("@nom", SqlDbType.VarChar, 50)
objParam.Value = nom.Text
'-------------------------------------
' Prepare table as parameter
'-------------------------------------
dtc_KeywordsID = New DataColumn()
dtc_KeywordsID.ColumnName = "id_produit"
dt_KeywordsID.Columns.Add(dtc_KeywordsID)
'-------------------------------------
' Store procedure execution
'-------------------------------------
objCommand.ExecuteNonQuery()
'-------------------------------------
' Close the connexion object
'-------------------------------------
objCommand.Connection.Close()
'-------------------------------------------
'verifier si tous les champs sont remplis
'-------------------------------------------
Else
'Erreur
lbl_error.Visible = True
End If
'---------------------------
'message de confirmation
'---------------------------
Session("lblmessage") = "l'ajout est bien effectuer"
Response.Redirect("message.aspx")
End Sub |
Partager