How can I delete specific record from mshflexgrid? For example mshflex grid is showing data from monthly_instal table. Now I want to delete record from this table. I have written code to delete record from that table but its deleting record one by one like 1 2 3 4. I want to delect specific record whatever it is 3 or 4 or 2 or 1. Even I have selected or marked row(specific record) then clicked on delete button but its not deleting what I want to delete! Its deleting data serially. So what should I do to delete specific data? I am using vb.net. Though nobody use mshflexgrid there in vb.net but I tried because of its facility. All I want to do it that I want to delete specific record from mshflex grid & it will shows another records there in grid without that record what I have deleted(I mean recordset will be updated & it will show records there in grid). Please check my code & help me to get rid of this problem & please dont forget to explain it by code because I am just a beginner.
My code : Public Class Form34
Private Sub Form34_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbdmidt.Items.Clear()
cmbdmidt.Text = "DATE"
con = New ADODB.Connection
con.Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SUIMT")
rst = New ADODB.Recordset
With rst
.Open("Select * From monthly_instal", con, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
If .BOF = False Then
.MoveFirst()
While .EOF = False
If Not cmbdmidt.Items.Contains(.Fields("dt").Value) Then
cmbdmidt.Items.Add(.Fields("dt").Value)
End If
.MoveNext()
End While
End If
.Close()
End With
Me.CREATEUSERToolStripMenuItem.Enabled = False
Me.DELETEUSERToolStripMenuItem.Enabled = False
Me.CHANGEPASSWORDToolStripMenuItem.Enabled = False
Me.ASSIGNPERMISSIONToolStripMenuItem.Enabled = False
Me.SHOWALLToolStripMenuItem.Enabled = False
Me.CREATEACADEMICYEARToolStripMenuItem.Enabled = False
Me.DELETEACADEMICYEARToolStripMenuItem.Enabled = False
Me.CREATESESSIONToolStripMenuItem.Enabled = False
Me.DELETESESSIONToolStripMenuItem.Enabled = False
Me.CREATEDEPARTMENTToolStripMenuItem.Enabled = False
Me.DELETEDEPARTMENTToolStripMenuItem.Enabled = False
Me.CREATEEXAMTYPEToolStripMenuItem.Enabled = False
Me.DELETEEXAMTYPEToolStripMenuItem.Enabled = False
Me.CREATESUBJECTToolStripMenuItem.Enabled = False
Me.DELETESUBJECTToolStripMenuItem.Enabled = False
Me.ADMISSIONToolStripMenuItem.Enabled = False
Me.DELETEADMISSIONToolStripMenuItem.Enabled = False
Me.ADMISSIONREPORTToolStripMenuItem.Enabled = False
Me.STUDENTINFORMATIONToolStripMenuItem.Enabled = False
Me.DELETESTUDENTINFORMATIONToolStripMenuItem.Enabled = False
Me.SEARCHSTUDENTINFORMATIONToolStripMenuItem.Enabled = False
Me.STUDENTINFORMATIONREPORTToolStripMenuItem.Enabled = False
Me.CREATESTUDENTRESULTToolStripMenuItem.Enabled = False
Me.DELETESTUDENTRESULTToolStripMenuItem.Enabled = False
Me.STUDENTRESULTREPORTToolStripMenuItem.Enabled = False
Me.RESULTSHEETREPORTToolStripMenuItem.Enabled = False
Me.CREATEMONTHLYINSTALLMENTToolStripMenuItem.Enabled = False
Me.DELETEMONTHLYINSTALLMENTToolStripMenuItem.Enabled = False
Me.MONTHLYINSTALLMENTREPORTToolStripMenuItem.Enabled = False
Me.CREATEBALANCESHEETToolStripMenuItem.Enabled = False
Me.DELETEBALANCESHEETToolStripMenuItem.Enabled = False
Me.BALANCESHEETREPORTToolStripMenuItem.Enabled = False
Me.ABOUTTHISPROGRAMToolStripMenuItem.Enabled = False
Me.EXIToolStripMenuItem.Enabled = False
End Sub
Private Sub ADMINISTRATIONToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ADMINISTRATIONToolStripMenuItem.Click
speak34.Speak("Administration")
End Sub
Private Sub STUDENTMANAGEMENTToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles STUDENTMANAGEMENTToolStripMenuItem1.Click
speak34.Speak("Student management")
End Sub
Private Sub ACCOUNTANCYToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ACCOUNTANCYToolStripMenuItem1.Click
speak34.Speak("Accountancy")
End Sub
Private Sub ABOUTITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ABOUTITToolStripMenuItem.Click
speak34.Speak("About it")
End Sub
Private Sub EXITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EXITToolStripMenuItem.Click
speak34.Speak("Exit")
End Sub
Private Sub cmbdmidt_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbdmidt.Leave
On Error Resume Next
rst = New ADODB.Recordset
With rst
.Open("Select stu_id, tot_amou, paid, du, aoins, due, dt from monthly_instal where dt = '" & cmbdmidt.Text & "'", con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
Mshgrid2.DataSource = rst
Mshgrid2.set_TextMatrix(0, 0, "ID NUMBER")
Mshgrid2.set_TextMatrix(0, 1, "TOTAL AMOUNT")
Mshgrid2.set_TextMatrix(0, 2, "PAID")
Mshgrid2.set_TextMatrix(0, 3, "DUE")
Mshgrid2.set_TextMatrix(0, 4, "AMOUNT OF INSTALLMENT")
Mshgrid2.set_TextMatrix(0, 5, "DUE")
Mshgrid2.set_TextMatrix(0, 6, "DATE")
Mshgrid2.set_ColWidth(0, 2000)
Mshgrid2.set_ColWidth(1, 2000)
Mshgrid2.set_ColWidth(2, 2000)
Mshgrid2.set_ColWidth(3, 2000)
Mshgrid2.set_ColWidth(4, 2000)
Mshgrid2.set_ColWidth(5, 2000)
Mshgrid2.set_ColWidth(6, 2000)
.Close()
End With
End Sub
Private Sub butdmiclo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butdmiclo.Click
speak34.Speak("Delete monthly installment window has been closed successfully")
Me.Close()
End Sub
Private Sub butdmidel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butdmidel.Click
With rst
.Open("Select * From monthly_instal where dt = '" & cmbdmidt.Text & "'", con, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
.Delete()
.Close()
cmbdmidt.Text = "DATE"
cmbdmidt.Items.Clear()
End With
rst = New ADODB.Recordset
With rst
.Open("Select * From monthly_instal", con, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
If .BOF = False Then
.MoveFirst()
While .EOF = False
If Not cmbdmidt.Items.Contains(.Fields("dt").Value) Then
cmbdmidt.Items.Add(.Fields("dt").Value)
End If
.MoveNext()
End While
End If
.Close()
End With
Mshgrid2.Clear()
Mshgrid2.set_TextMatrix(0, 0, "ID NUMBER")
Mshgrid2.set_TextMatrix(0, 1, "TOTAL AMOUNT")
Mshgrid2.set_TextMatrix(0, 2, "PAID")
Mshgrid2.set_TextMatrix(0, 3, "DUE")
Mshgrid2.set_TextMatrix(0, 4, "AMOUNT OF INSTALLMENT")
Mshgrid2.set_TextMatrix(0, 5, "DUE")
Mshgrid2.set_TextMatrix(0, 6, "DATE")
Mshgrid2.set_ColWidth(0, 2000)
Mshgrid2.set_ColWidth(1, 2000)
Mshgrid2.set_ColWidth(2, 2000)
Mshgrid2.set_ColWidth(3, 2000)
Mshgrid2.set_ColWidth(4, 2000)
Mshgrid2.set_ColWidth(5, 2000)
Mshgrid2.set_ColWidth(6, 2000)
speak34.Speak("Monthly installment has been deleted successfully")
End Sub
End Class