Utilisation bizarre de requête d'insertion, suppression
Bonjour,
Je reprend un programme et la façon d'utiliser les requêtes d'insertion, mise à jour et suppression me surprennent.
la variable "sQuery" contient la requête. (INSERT INTO table ...) ou (DELETE FROM ...) etc.
Code:
1 2 3 4 5 6 7 8 9 10 11
| Dim oConnection As New System.Data.SqlClient.SqlConnection(ConnStr)
oConnection.Open()
Dim cmd As New SqlClient.SqlCommand(sQuery, oConnection)
cmd.CommandType = CommandType.Text
Dim Oda As New SqlClient.SqlDataAdapter
Oda.SelectCommand = cmd
Dim MyDs As New DataSet
Try
Oda.Fill(MyDs)
Catch ex As Exception
... |
Cela fonctionne mais ...
J'utilise plutôt cette façon de faire avec une commande "ExecuteNonQuery"
Code:
1 2 3 4 5 6 7 8
| Dim oConnection As New SqlConnection(ConnStr)
Try
oConnection.Open()
Dim oCommand As New SqlCommand(sQuery, oConnection)
oCommand.CommandType = CommandType.Text
oCommand.ExecuteNonQuery()
Catch Ex As Exception
... |
Qu'en pensez-vous?
A+, Hervé.