Quel est ce mode

Résolu
mohamed3000 Messages postés 8 Date d'inscription jeudi 19 mai 2005 Statut Membre Dernière intervention 23 septembre 2009 - 23 sept. 2009 à 03:42
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 - 23 sept. 2009 à 08:49
Imports System.Data.SqlClient

Public Class Form1

Public myConnection As SqlConnection
Public myCommand As SqlCommand
Public dr As SqlDataReader
'declaring the objects need

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

myConnection = New SqlConnection("Data Source=mop-2FB1429;Initial Catalog=base1;Integrated Security=True")
'establishing connection
Try
myConnection.Open()
'opening the connection
myCommand = New SqlCommand("Select * from client", myConnection)
'executing the command and assigning it to connection
dr = myCommand.ExecuteReader()
While dr.Read()
'reading from the datareader
MessageBox.Show("nom" & dr(0).ToString())
MessageBox.Show("prenom" & dr(1).ToString())

End While
dr.Close()
myConnection.Close()
Catch ex As Exception
End Try
End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

myConnection.Open()
myCommand = myConnection.CreateCommand

myCommand.CommandText = "insert into client(nom,prenom)values('" & TextBox1.Text & "','" & TextBox2.Text & "' ) "

myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub
End Class

___________________________________________________
Bonjours

C'est le mode connecté ou déconnecté
?

1 réponse

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 72
23 sept. 2009 à 08:49
utilises des requetes parametrées, pour eviter l'injection SQL ou des erreurs bêtes...

tapes D'Avoine comme nom de famille puor le client a ajouter pour t'en convaincre.


de même, ne fais pas de SELECT * si tu ne requiert que deux champs nom et prenom...


concernant ces 'modes', il s'agit de déterminer si ton recordset prend une photo de ta base a un instant t (deconnecté) ou est a jour à tout instant (connecté)

Renfield - Admin CodeS-SourceS - MVP Visual Basic
3