How do you clear a dataset?

  • Thread starter Thread starter tfs
  • Start date Start date
T

tfs

I have the following code:

The following line is global

Dim sqlDS = New DataSet()

This is in a procedure

objConnect.Open()
sqlDA = New SqlDataAdapter("select * from
eventCalendar",objConnect)
sqlDA.Fill(sqlDS,"eventCalendar")
Dim totalRows as integer
Dim totalColumns as integer
Dim GetRows as DataTable =
sqlDS.tables("eventCalendar")


My problem is that when I do the fill, it seems to be appending to
what was in the old Dataset (sqlDS - Since it is global).

I want to clear the sqlDS before I do the fill.

How would I do this?

Thanks,

Tom.
 
Hi TFS

sqlDS = nothing
or
dim SqlDS as Dataset
and than in your methode
sqlDs = New Dataset

I hope that helps?

Cor
 
Hi,

You can sqlDS.Clear()

Or sqlDS=New DataSet(), then you can a totally new DataSet.

Garbage Collector must delete the old DataSet. (I think, it doesn't make
always.)

Laszlo

tfs said:
I have the following code:

The following line is global

Dim sqlDS = New DataSet()

This is in a procedure

objConnect.Open()
sqlDA = New SqlDataAdapter("select * from
eventCalendar",objConnect)
sqlDA.Fill(sqlDS,"eventCalendar")
Dim totalRows as integer
Dim totalColumns as integer
Dim GetRows as DataTable =
sqlDS.tables("eventCalendar")


My problem is that when I do the fill, it seems to be appending to
what was in the old Dataset (sqlDS - Since it is global).

I want to clear the sqlDS before I do the fill.

How would I do this?

Thanks,

Tom.
 
My problem is that when I do the fill, it seems to be appending to
what was in the old Dataset (sqlDS - Since it is global).
I want to clear the sqlDS before I do the fill.
How would I do this?

Couldn't you just do:

sqlDS = New DataSet()

right before the fill?

Chris
 
Hi

Try DataSet.Clear method.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

tfs said:
I have the following code:

The following line is global

Dim sqlDS = New DataSet()

This is in a procedure

objConnect.Open()
sqlDA = New SqlDataAdapter("select * from
eventCalendar",objConnect)
sqlDA.Fill(sqlDS,"eventCalendar")
Dim totalRows as integer
Dim totalColumns as integer
Dim GetRows as DataTable =
sqlDS.tables("eventCalendar")


My problem is that when I do the fill, it seems to be appending to
what was in the old Dataset (sqlDS - Since it is global).

I want to clear the sqlDS before I do the fill.

How would I do this?

Thanks,

Tom.
 
Try this

sqlDA = New SqlDataAdapter("select * from eventCalendar",objConnect)
If sqlDS.Tables.Contains("eventCalendar") Then
sqlDS.Tables("eventCalendar").Clear()

sqlDA.Fill(sqlDS,"eventCalendar")





tfs said:
I have the following code:

The following line is global

Dim sqlDS = New DataSet()

This is in a procedure

objConnect.Open()
sqlDA = New SqlDataAdapter("select * from
eventCalendar",objConnect)
sqlDA.Fill(sqlDS,"eventCalendar")
Dim totalRows as integer
Dim totalColumns as integer
Dim GetRows as DataTable =
sqlDS.tables("eventCalendar")


My problem is that when I do the fill, it seems to be appending to
what was in the old Dataset (sqlDS - Since it is global).

I want to clear the sqlDS before I do the fill.

How would I do this?

Thanks,

Tom.
 
If you have a global dataset, you will more likely wish to clear the
datatable within the dataset instead of clearing all tables/all data from
the dataset.

sqlDS.tables("eventCalendar").Clear()


tfs said:
I have the following code:

The following line is global

Dim sqlDS = New DataSet()

This is in a procedure

objConnect.Open()
sqlDA = New SqlDataAdapter("select * from
eventCalendar",objConnect)
sqlDA.Fill(sqlDS,"eventCalendar")
Dim totalRows as integer
Dim totalColumns as integer
Dim GetRows as DataTable =
sqlDS.tables("eventCalendar")


My problem is that when I do the fill, it seems to be appending to
what was in the old Dataset (sqlDS - Since it is global).

I want to clear the sqlDS before I do the fill.

How would I do this?

Thanks,

Tom.
 
Back
Top