You are on page 1of 2

Option Explicit Dim rs As New ADODB.Recordset Private Sub Command1_Click() Set rs = New ADODB.Recordset rs.

Open "Select * from tbl_studinfo where " & Combo1.Text & "='" & Text1.Text & "'", con, adOpenDynamic, adLockBatchOptimistic Set DataGrid1.DataSource = rs

End Sub - _ - - - - - CODE FOR DELETE- - - - - - - Private Sub Command2_Click() Dim x As Integer If DataGrid1.ApproxCount >= 1 Then If x = vbYes Then con.Execute "DELETE FROM tbl_studinfo where id=" & DataGrid1.Columns(0).Text & "" MsgBox "hooray data delete" Filldatagrid Else MsgBox "Operation cancelled" End If x = MsgBox("do you realy want to delete this file", vbYesNo, "DELETING") Else MsgBox "CAN'T PERFORM DELETE ACTION" End If End Sub Private Sub Command3_Click() On Error Resume Next con.Execute "Insert into tbl_studinfo (fullname,age,gender,course,yr) values('" & Text2.Text & _ "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "');" MsgBox "hooray data has been save successfully" Filldatagrid End Sub Private Sub Form_load() Filldatagrid End Sub Private Sub Filldatagrid() Dim i As Integer Set rs = New ADODB.Recordset rs.Open "Select * from tbl_studinfo", con, adOpenDynamic, adLockBatchOptimistic Set DataGrid1.DataSource = rs For i = 0 To 5 Combo1.AddItem DataGrid1.Columns(i).Caption Next i

End Sub

You might also like