Click here to Skip to main content
15,909,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys,

Can't Delete row in the DataGridView1. It pulls the whole records from MS Access Database and display them in the DataGridView1.

Can anyone help?

While in the Table (Payroll), it has the following fields;
1.	fromDate  = Date/Time
2.	ToDate = Date/Time
3.	EmpID = Text
4.	WorkDays = Number
5.	DialyRate = Currency
6.	Total = Currency
7.	RegOT = Currency
8.	RegOTTotal = Currency
9.	SunOT = Currency
10.	SunOTTotal = Currency
11.	HolPay = Currency
12.	HolPayTotal = Currency
13.	Allowances = Currency
14.	Incentives = Currency
15.	EmployerContributions = Currency
16.	Others = Currency
17.	GROSS = Currency
18.	EmployeeContribution = Currency
19.	Loans = Currency
20.	GovTax = Currency
21.	Late = Currency
22.	OtherDeduction = Currency
23.	TotalDeductions = Currency
24.	NetPayment = Currency


VB
Imports System.Data.OleDb
Public Class DeletePayroll
    Dim CnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" & Application.StartupPath & "\EmployeesInfo.mdb;Jet OLEDB:Database Password=employees"
    Dim Con As New OleDbConnection(CnString)
    Dim CMD As New OleDbCommand
    Dim strselectedEmpID As String

   
    Private Sub DeletePayroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Con.Open()
        filldata()
        Con.Close()
    End Sub


    Private Sub filldata()
        Dim da As New OleDbDataAdapter("select * from Payroll Order by EmpID", Con)
        Dim ds As New DataSet
        da.Fill(ds, "Payroll")
        DataGridView1.DataSource = ds.Tables("Payroll")
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Con.Open()

        Dim cmd As New OleDbCommand("delete * from Payroll where EmpID='" & strselectedEmpID & "'", Con)
        cmd.ExecuteNonQuery()
        MsgBox("Data Deleted Successfully", MsgBoxStyle.Exclamation, "Delete Record")
        filldata()
        Con.Close()
    End Sub    
End Class
Posted
Updated 26-Sep-13 5:22am
v4
Comments
Debug and see whether there are any issues or not. You must be getting some Exceptions.
Manoj K Bhoir 27-Sep-13 1:09am    
Debug and check value of strselectedEmpID also use Try Catch Block While Executing the Query to handle Exceptions.

1 solution

Replace Delete * With Just "Delete From ..." ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900