[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

vb.net datatable .clear method issue

Posted on 2011-09-02
9
Medium Priority
?
670 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 36472726
Dim cv As DataTable = New DataTable("MES")
cv.Rows.Clear()
cv.AcceptChanges()

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:michael_krell
ID: 36472738
I have tried that.... sorry
0
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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