回 帖 发 新 帖 刷新版面

主题:请问删除DataGrid中内容的问题.谢谢

我给DataGrid设置了Delete按钮,我想在点击该按钮后就把指定的这一行删除.
但是我看到很多书上写的都是在数据库里删除这一行,再在DataGrid里重新显示.
我想要的效果是只是在DataGrid中删除这一行而已.并不要在数据库中去删除.
希望能解答一下,谢谢~

回复列表 (共1个回复)

沙发

我调了一下,这个可以实现。不知是否达到你的要求
Imports System.Data
Imports System.Data.OleDb

Public Class Form2
    Inherits System.Windows.Forms.Form
    Dim dbset As New DataSet

  Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim constr As String = "provider=microsoft.jet.oledb.4.0;data source=e:\VB.NETziliao\publicdatabase\db1.mdb"
        Dim mycon As New OleDb.OleDbConnection(constr)

        Dim str As String

        str = "select id as id,xuehao as 学号,xingming as 姓名,kemufenshu as 科目分数,banjimingcheng as 班名称 from chengji    "
        Dim adp As New OleDbDataAdapter(str, constr)
        adp.Fill(dbset, "aa")
        DataGrid1.DataSource = dbset.Tables("aa")


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim row As Integer
        row = DataGrid1.CurrentRowIndex
        dbset.Tables("aa").Rows(row).Delete()
        dbset.Tables("aa").AcceptChanges()
    End Sub
End Class

我来回复

您尚未登录,请登录后再回复。点此登录或注册