无法删除DataGridView中的Row和Table中的记录 [英] Can't Delete Row in the DataGridView and the record in Table

查看:52
本文介绍了无法删除DataGridView中的Row和Table中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



无法删除 DataGridView1 中的行。它从 MS Access数据库中提取整个记录,并在 DataGridView1 中显示它们。



任何人都可以帮忙吗?



在表格(工资单)中,它有以下字段;

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







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

推荐答案

使用从...删除替换删除*;)
Replace Delete * With Just "Delete From ..." ;)


这篇关于无法删除DataGridView中的Row和Table中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆