hi all
I have an exercise
when I select the value in the combobox will confirm the value on datagridview
I wrote a code in combobox of from1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sQry As String
sQry = "SELECT Name FROM dtaStudent"
Dim con As SqlConnection = New SqlConnection(sqldb.ConnectionString)
Dim da As SqlDataAdapter = New SqlDataAdapter(sQry, con)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "ID"
ComboBox1.DataSource = dt
ComboBox1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'code
form2.ShowDialog()
End Sub
http://s27.postimg.org/4blpooo8j/Untitled.jpg
I wrote a code in datagridview of from2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sqlQuery As String = "SELECT ID,Name from dtaStudent "
Dim conn As SqlConnection = New SqlConnection(sqldb.ConnectionString)
conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(sqlQuery, conn)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
http://s26.postimg.org/sc7097pcp/Untitled1.jpg
put value on combobox is name
when selected value
if datagridview cell is empty it will error
I want to select the ID instead of Name
because ID is always fixed
but do not know how
expect people to help