Private con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\foro.accdb") Private cmd As New OleDbCommand(""SELECT PRATICIEN FROM PRATICIENS"", con) Private rd As OleDbDataReader Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try con.Open() rd = cmd.ExecuteReader While rd.Read ComboBox1.Items.Add(rd(0)) End While con.Close() Catch ex As Exception End Try End Sub Private Sub txtdocteur_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtdocteur.Validating Dim sqltxt As String = "Insert into Essai values('" + ComboBox1.Text.ToUpper + "')" Dim cmd As New OleDbCommand(sqltxt , con) Try con.Open() cmd.ExecuteNonQuery() con.Close() Catch ex As Exception End Try End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate cmd As New OleDbCommand("SELECT PRATICIEN FROM PRATICIENS", con)
Imports System.Data.SqlClient Public Class Form1 Private con As New SqlConnection("Data Source=ICONIC_D-PC\SQLEXPRESS;Initial Catalog=Essai;Integrated Security=True") Private cmd As New SqlCommand("select Name from Essai", con) Private rd As SqlDataReader Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try con.Open() rd = cmd.ExecuteReader While rd.Read ComboBox1.Items.Add(rd(0)) End While con.Close() Catch ex As Exception Debug.Print(ex.ToString) End Try End Sub Private Sub ComboBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox1.Validating Dim h As String = "Insert into Essai values('" + ComboBox1.Text.ToUpper + "')" Dim cmd2 As New SqlCommand(h, con) Try con.Open() cmd2.ExecuteNonQuery() con.Close() Catch ex As Exception End Try End Sub
ComboBox1.Items.Add(rd(0))
ComboBox1.Items.Add(rd("Name").ToString)