user2951524
user2951524

Reputation: 67

clear all records from data set in vb.net

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

  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

Upvotes: 3

Views: 22146

Answers (1)

Steve
Steve

Reputation: 216313

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

 ds.Clear()

MSDN reference 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.

Upvotes: 5

Related Questions