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
| Protected Sub code_activite_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles code_activite.SelectedIndexChanged
Dim maConnexionSQLsrv As IDbConnection
Dim myCommand As IDbCommand
Dim maRequete, ConnexionSQL As String
'Récupération de la chaine de connexion au serveur de base de données
ConnexionSQL = ConfigurationSettings.AppSettings("ConnectionStringSQLsrv")
maConnexionSQLsrv = IDbConnection(ConnexionSQL)
'requete
maRequete = "Select code_activite from(dbo.activite) where id_projet=@id_projet"
'Création de la commande SQL
myCommand = IDbCommand(maRequete, maConnexionSQLsrv)
'Création et décalartion des paramètres
With myCommand.Parameters
.Add(Parameter("@id_projet", SqlDbType.Int, 4))
End With
'Attribution des valeurs aux paramètres
With myCommand
.Parameters("@id_projet").Value = DropDownList
End With
Try
'Execution de la requête
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Class |