Mine SQL table is
Expand|Select|Wrap|Line Numbers
- create database student
- use student
- create table stu_table(roll int primary key,name varchar(10),
- marks int)
Expand|Select|Wrap|Line Numbers
- select * from stu_table
On form1 I have Combobox named cmbroll and DataGriDview
In the combroll I retrieved all the roll that are in the database on the form1_load.
When I select roll 1 from cmbroll then in Gridview Corresponding name & marks are displayed.
And the Foll. Code Retrives the data From the Database into the dataGridview--
Expand|Select|Wrap|Line Numbers
- Private Sub cmbRoll_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbRoll.SelectedIndexChanged
- Try
- If con.State = 1 Then
- con.Close()
- End If
- con.Open()
- RS.Open("select name,marks from stu_table where roll='" & Me.cmbRoll.Text & "'", con, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockBatchOptimistic)
- obj.DataGridView1.Item(0, 0).Value = RS.Fields(0).Value.ToString
- obj.DataGridView1.Item(1, 0).Value = RS.Fields(1).Value.ToString
- Catch ex As Exception
- MsgBox(ex.Message)
- Finally
- If con.State = 1 Then
- con.Close()
- End If
- End Try
- End Sub