how to get the selected value from DataGridViewComboBoxColumn to save in MySQL DB?

  • Thread starter Thread starter Apostolos Doudakmanis
  • Start date Start date
A

Apostolos Doudakmanis

Guest
I have a DataGridViewComboBoxColumn loaded with data from MySQ on DataGridView

DROP TABLE IF EXISTS `pin10`;
CREATE TABLE IF NOT EXISTS `pin10` (
`id` int(11) NOT NULL,
`f1` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Imports MySql.Data.MySqlClient

Dim combo As New DataGridViewComboBoxColumn

Sub LoadComboBox()
Dim strSQL As String

OpenDB()
strSQL = "Select * From Pin10"

ds1 = New DataSet
tables1 = ds1.Tables
da1 = New MySqlDataAdapter(strSQL, myConnection2)
da1.Fill(ds1, "Pin10")
Dim view1 As New DataView(tables1(0))

combo.DataSource = view1
CloseDB()
End Sub

Public Sub ReadDB()
Dim strSQL As String

LoadComboBox()

OpenDB()

strSQL = "Select p11.id, p11.f1, p11.f2, "
strSQL = strSQL + "p11.f3, "
strSQL = strSQL + "p10.f1, "
strSQL = strSQL & " From Pin11 as p11 "
strSQL = strSQL & " LEFT JOIN pin10 AS p10 ON p11.f7=p10.id "
strSQL = strSQL & " order by p11.ID "

ds = New DataSet
tables = ds.Tables
da = New MySqlDataAdapter(strSQL, myConnection2)
da.Fill(ds, "Pin11")
Dim view As New DataView(tables(0))
source1.DataSource = view

DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = view

Dim colId As New DataGridViewTextBoxColumn()
colId.DataPropertyName = "Id"
colId.HeaderText = "A/A"
DataGridView1.Columns.Add(colId)

Dim colf1 As New DataGridViewTextBoxColumn()
colf1.DataPropertyName = "f1"
colf1.HeaderText = "Name"
colf1.Width = 200
DataGridView1.Columns.Add(colf1)

Dim colf2 As New DataGridViewTextBoxColumn()
colf2.DataPropertyName = "f2"
colf2.HeaderText = "Type"
colf2.Width = 100
DataGridView1.Columns.Add(colf2)

Dim colf3 As New DataGridViewCheckBoxColumn
colf3.DataPropertyName = "f3"
colf3.HeaderText = "Value 1"
colf3.Width = 100
DataGridView1.Columns.Add(colf3)

combo.ValueMember = "id"
combo.DisplayMember = "f1"
combo.DataPropertyName = "f110"
combo.HeaderText = "Type Account"
DataGridView1.Columns.Add(combo)

DataGridView1.Refresh()

CloseDB()
End Sub


When I changed the value in the DataGridViewComobBoxColumn, how can I get the new values (id and f1) and store them back the base with commands INSERT and UPDATE?

Continue reading...
 
Back
Top