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
| Imports System.Data
Imports System.Data.OleDb
Partial Class plaques
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Try
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ChaineConnexion").ConnectionString
Dim connection As New Data.OleDb.OleDbConnection(connectionString)
connection.Open()
'verifier si la date n'existe pas
Dim sql_verif As String = "select count(*) from plaques where [date]='" & TextBox1.Text & "'"
Dim verif As New Data.OleDb.OleDbCommand(sql_verif, connection)
Dim n As Integer
n = CType(verif.ExecuteScalar(), Integer)
Label3.Text = n
If n = 0 Then
Dim sql As String = "INSERT INTO plaques ([date], [nbre_plaques]) VALUES ('" & TextBox1.Text & "', '" & TextBox2.Text & "')"
Dim myCommand As New Data.OleDb.OleDbCommand(sql, connection)
myCommand.ExecuteNonQuery()
Label3.Text = "La date a été ajouté ainsi que le nombre de plaques!"
Else
Label3.Text = "La date existe déjà"
End If
'Catch err As Exception
' Label3.Text = Err.Message
'Finally
connection.Close()
' End Try
End Sub
End Class |
Partager