Solved

vb.net datatable .clear method issue

Posted on 2011-09-02
9
642 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:michael_krell
  • 5
  • 4
9 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 36472700
try calling the reset method, i.e
Dim cv As DataTable = New DataTable("MES")
cv.Reset()

Open in new window

0
 

Author Comment

by:michael_krell
ID: 36472712
I believe when i did that it killed everything. meaning my columns were gone as well.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 36472726
Dim cv As DataTable = New DataTable("MES")
cv.Rows.Clear()
cv.AcceptChanges()

Open in new window

0
 

Author Comment

by:michael_krell
ID: 36472738
I have tried that.... sorry
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 17

Expert Comment

by:nepaluz
ID: 36472747
Hmmm!! Be right back. (would help if you show some code on how the table is set up)
0
 

Author Comment

by:michael_krell
ID: 36472905
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
 

Author Comment

by:michael_krell
ID: 36473277
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
 
LVL 17

Expert Comment

by:nepaluz
ID: 36474941
stranger things have happened I suppose .... care to share so we can avoid the same?
0
 

Author Comment

by:michael_krell
ID: 36483757
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now