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
| Dim newCable As String = InputBox("Ajouter Un Type de Cable", "Nouveau", "Entrer", 4, 4)
If Len(Trim(newCable)) > 0 Then
Dim strConn As String = "Server=DEV-PC;Database=MaBase;Trusted_Connection=True;"
Using connection As New SqlConnection(strConn)
Try
connection.Open()
'MessageBox.Show("Connection ouverte")
Dim requete As String = "INSERT INTO Cables (Type) VALUES (@TypeCable)"
Dim myCommand As SqlCommand = New SqlCommand(requete, connection)
myCommand.Parameters.Add(New SqlParameter("@TypeCable", SqlDbType.VarChar))
myCommand.Parameters("@TypeCable").Value = newCable
myCommand.ExecuteNonQuery()
MessageBox.Show("Nouvelle ligne ajoutée avec succès!", "Cool", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
If ex.HResult = -2146232060 Then
MessageBox.Show("Ce cable existe déjà dans la base de données", "Risque de doublons", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Erreur : " & ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Try
End Using
Else
MessageBox.Show("Aucun type de cable saisi", "Pas de données fournies", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If |
Partager