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 42 43 44 45 46 47 48 49 50
| Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private StringConnection As String = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=TEST;Integrated Security=SSPI;"
Private Connection As OleDbConnection
Private ManipulationDonnees As OleDbDataAdapter
Private TableDonnees As DataTable
Private StrSqlComboBox1 As String = "Select TEST_Valeur2 FROM TEST ORDER BY TEST_Valeur2"
Private StrSqlDataViewGrid1 As String = "SELECT * FROM TEST"
Private StrSql As String
Private CommandeSQL As OleDbCommand
Sub CNX()
Connection = New OleDbConnection(StringConnection)
Connection.Open()
End Sub
Sub Loab_DataGridView1()
DataGridView1.Refresh()
ManipulationDonnees = New OleDbDataAdapter(StrSqlDataViewGrid1, Connection)
TableDonnees = New DataTable()
ManipulationDonnees.Fill(TableDonnees)
DataGridView1.DataSource = TableDonnees
End Sub
Sub Load_ComboBox1()
ComboBox1.Refresh()
ManipulationDonnees = New OleDbDataAdapter(StrSqlComboBox1, Connection)
TableDonnees = New DataTable()
ManipulationDonnees.Fill(TableDonnees)
ComboBox1.DataSource = TableDonnees
ComboBox1.DisplayMember = "TEST_Valeur2"
End Sub
Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
StrSql = "INSERT INTO TEST(TEST_Valeur1, TEST_Valeur2, TEST_Valeur3) VALUES ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "')"
CommandeSQL = New OleDbCommand(StrSql, Connection)
CommandeSQL.ExecuteNonQuery()
Loab_DataGridView1()
Load_ComboBox1()
End Sub
Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CNX()
Load_ComboBox1()
Loab_DataGridView1()
End Sub
End Class |
Partager