Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim connexion As New SqlConnection("Data Source=(local)\SQLEXPRESS";Integrated Security=false;Initial Catalog=mabase;User ID=login;PWD=password")
Dim add As SqlCommand = New SqlCommand(requete, connexion) Try add.ExecuteNonQuery() Catch msg As SqlException MsgBox(msg.Message, MsgBoxStyle.Exclamation + vbOKOnly, "Attention") Return False Exit Function End Try
Dim myreq As SqlCommand = New SqlCommand(requete, connexion) myreader = myreq.ExecuteReader() Return myreader myreader.Close()
Dim connexion As New SqlConnection("Data Source=(local)\SQLEXPRESS;Integrated Security=false;Initial Catalog=mabase;User ID=login;PWD=password")
Dim add As SqlCommand = New SqlCommand("insert into matable", connexion) Try add.ExecuteNonQuery() Catch msg As SqlException MsgBox(msg.Message, MsgBoxStyle.Exclamation + vbOKOnly, "Attention") Return False Exit Function End Try
Dim myreq As SqlCommand = New SqlCommand("select * from matable", connexion) myreader = myreq.ExecuteReader() Return myreader myreader.Close()
Imports System.Data.SqlClient Public Class Form1 Private Sub Button_Read_Click() Handles Button1.Click 'Chaine de connexion Dim ConnectionSrting As String = "Ma chaine de connexion" 'Objet connexion (Instance de la classe SqlConnection) Dim Connection As New SqlConnection(ConnectionSrting) '----------------------------------------------- 'Méthode en mode connecté '----------------------------------------------- 'Requête SQL de sélection Dim CommandText As String = "SELECT * FROM Contacts" 'Objet Command (Instance de la classe SqlConnection) Dim Command As New SqlCommand(CommandText, Connection) ' Try ' 'Ouverture de la connexion Connection.Open() ' 'Objet MyDataReader (Instance de la classe SqlDataReader) Dim MyDataReader As SqlDataReader = Command.ExecuteReader While MyDataReader.Read 'Lecture des enregistrements... End While ' Catch ex As Exception ' 'Gestion des erreurs ' Finally ' 'Fermeture de la connexion si ouverte If Connection.State <> ConnectionState.Closed Then Connection.Close() End If ' End Try ' '----------------------------------------------- 'Méthode en mode déconnecté '----------------------------------------------- ' Try 'Objet MyDataAdapter (Instance de la classe SqlDataAdapter) Dim MyDataAdapter As New SqlDataAdapter(CommandText, Connection) ' 'Objet MyDataTable (Instance de la classe DataTable) Dim MyDataTable As New DataTable MyDataAdapter.Fill(MyDataTable) For Each Row As DataRow In MyDataTable.Rows 'Lecture des données Next Catch ex As Exception ' 'Gestion des erreurs ' End Try ' End Sub ' End Class
Imports System.Data.SqlServerCe Public Class Form1 Private Sub Button_Read_Click() Handles Button1.Click 'Chaine de connexion Dim ConnectionSrting As String = "Ma chaine de connexion" 'Objet connexion (Instance de la classe SqlConnection) Dim Connection As New SqlCeConnection(ConnectionSrting) '----------------------------------------------- 'Méthode en mode connecté '----------------------------------------------- 'Requête SQL de sélection Dim CommandText As String = "SELECT * FROM Contacts" 'Objet Command (Instance de la classe SqlConnection) Dim Command As New SqlCeCommand(CommandText, Connection) ' Try ' 'Ouverture de la connexion Connection.Open() ' 'Objet MyDataReader (Instance de la classe SqlDataReader) Dim MyDataReader As SqlCeDataReader = Command.ExecuteReader While MyDataReader.Read 'Lecture des enregistrements... End While ' Catch ex As Exception ' 'Gestion des erreurs ' Finally ' 'Fermeture de la connexion si ouverte If Connection.State <> ConnectionState.Closed Then Connection.Close() End If ' End Try ' '----------------------------------------------- 'Méthode en mode déconnecté '----------------------------------------------- ' Try 'Objet MyDataAdapter (Instance de la classe SqlDataAdapter) Dim MyDataAdapter As New SqlCeDataAdapter(CommandText, Connection) ' 'Objet MyDataTable (Instance de la classe DataTable) Dim MyDataTable As New DataTable MyDataAdapter.Fill(MyDataTable) For Each Row As DataRow In MyDataTable.Rows 'Lecture des données Next Catch ex As Exception ' 'Gestion des erreurs ' End Try ' End Sub ' End Class