vb.net datatable .clear method issue

So i am trying to clear a datatable using the .clear() method for the table.

The issue i am running into is even though the table is cleared and there is no data in it i am getting an exception when i try to add data back into it.

Column 'DelayId' is constrained to be unique.  Value '2440' is already present.

so it seems like there is data already there, but when i check the row count before this code is executed it is 0. also i have tried .AcceptChanges() after the clear and it doesnt seem to make a difference.

I must be missing somethign stupid. Please help Thanks
michael_krellAsked:
Who is Participating?
 
nepaluzConnect With a Mentor Commented:
Dim cv As DataTable = New DataTable("MES")
cv.Rows.Clear()
cv.AcceptChanges()

Open in new window

0
 
nepaluzCommented:
try calling the reset method, i.e
Dim cv As DataTable = New DataTable("MES")
cv.Reset()

Open in new window

0
 
michael_krellAuthor Commented:
I believe when i did that it killed everything. meaning my columns were gone as well.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
michael_krellAuthor Commented:
I have tried that.... sorry
0
 
nepaluzCommented:
Hmmm!! Be right back. (would help if you show some code on how the table is set up)
0
 
michael_krellAuthor Commented:
This is the code for how the table is setup
With PopStartIDs
            .TableName = "PopStartIDs"
            .Columns.Add("DelayId")
            .PrimaryKey = New DataColumn() {.Columns("DelayID")}
            .Columns("DelayId").Unique = True

        End With

Open in new window

0
 
michael_krellAuthor Commented:
ok. so i may have figured it out.......

Looks like i was doing some stupid stuff with the data i was loading into it....
0
 
nepaluzCommented:
stranger things have happened I suppose .... care to share so we can avoid the same?
0
 
michael_krellAuthor Commented:
Nothing complicated. I had a dataset that I was filling with data and using a dataadapter and .fill method. Whenever that code ran it added new records instead of replacing. I just cleared the table in the SQL dataset before running the .fill
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.