清除 vb.net 中数据集中的所有记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19950396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:47:52  来源:igfitidea点击:

clear all records from data set in vb.net

vb.netdataset

提问by user2951524

i am working on vb.net windows form..in my button click i have given code like this:

我正在处理 vb.net windows 表单..在我的按钮单击中,我给出了这样的代码:

  Dim rpt As New DelivaryPerformance
     Dim ds As New DataSet
       Dim da As New SqlDataAdapter
         Dim rpt As New DelParkingtype
        Dim locid As Integer = RecordID("Locid", "Location_tbl", "LocName", CmbLocations.Text)
        Dim cmdstatus As New SqlCommand("IBS_DelivaryStaus", con.connect)
        cmdstatus.CommandType = CommandType.StoredProcedure
        cmdstatus.Parameters.Add("@locid", SqlDbType.Int).Value = locid
        da.SelectCommand = cmdstatus
        da.Fill(ds)
        If (ds.Tables(0).Rows.Count > 0) Then

            rpt.SetDataSource(ds.Tables(0))
            ' CrystalReportViewer1.ReportSource = rpt
        End If

while i am clicking each time in my button click,,i want to clear all records from my data set,,how i can clear my all records from my dataset

当我每次点击按钮时,我想清除数据集中的所有记录,如何清除数据集中的所有记录

回答by Steve

If you want to clear all rows from the tables contained in a dataset you could use

如果要清除数据集中包含的表中的所有行,可以使用

 ds.Clear()

MSDN reference DataSet.Clear

MSDN 参考 DataSet.Clear

This however, removes the records, not the tables schema. If you want to get rid of the tables also then you need to use

但是,这会删除记录,而不是表模式。如果你也想摆脱表格,那么你需要使用

 ds.Tables.Clear()

However, in the context of your code, the dataset is created as new, and so it is already empty until you fill it with the appropriate command, so it is not clear in which context you need to empty it.

但是,在您的代码上下文中,数据集是作为新创建的,因此在您使用适当的命令填充它之前它已经是空的,因此不清楚您需要在哪个上下文中清空它。