To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Feb 20th, 2007, 05:28 PM   #1
Genom
Addicted Member
 
Genom's Avatar
 
Join Date: May 06
Posts: 178
Genom is on a distinguished road (10+)
Question [2005] "A DataTable named 'Stok' already belongs to this DataSet."

Hi;
I try to get informations from an Access DB. There is tabcontrol. There are some tabstops. If you enter a tabstop it tries to update data in Datagridview. But at the first time you enter to tabstop it normally takes data from database. If you try to take data for a second time you need to do this:

VB Code:
  1. Me.DGW.DataSource = Nothing
  2.         DS.Tables.Clear()
  3.         DS.DataSetName = "NewDataSet"
  4.         CN.Close()
  5.         CNConnect()
  6.         RS.Open("SELECT * FROM " & TbStok & Ek, CN, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
  7.         TakeData()
  8.         ShowData()

and in this function I get the error, which is written in the title:

VB Code:
  1. Private Function TakeData() As Boolean
  2.        
  3.         DS.Tables.Add(TbStok)
  4.         OL.Fill(DS.Tables(TbStok), RS)
  5.         DS.DataSetName = CN.ConnectionString
  6.         DGW.DataSource = DS.Tables(TbStok)
  7.         Return True
  8.     End Function
But I clear the tables b4 using takedata function. There was a table with the same name from first taking data but in a second time I clear it b4 taking data again. What shall I do?
__________________
Dim Me As Coder
Genom is offline   Reply With Quote
Old Feb 20th, 2007, 05:31 PM   #2
techgnome
Invisible
 
Join Date: May 02
Posts: 13,261
techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)
Re: [2005] "A DataTable named 'Stok' already belongs to this DataSet."

1) Are you trying to use ADO or ADO.NET? Your code is using both. Pick one or the other and stick to it.

2) Yes, you are clearing the TABLES.... not the dataset.... big difference. Instead of using .CLEAR, check to see if the table exists in the Dataset first, then remove the table from the collection. Then you can fill it and add it back it.....

-tg
__________________
How to Use Parameters
* I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
* Got Eels in your Hovercraft? *
* Your guide to The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
*Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
* On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
"There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
MVP '06-'10
techgnome is offline   Reply With Quote
Old Feb 20th, 2007, 06:31 PM   #3
Genom
Addicted Member
 
Genom's Avatar
 
Join Date: May 06
Posts: 178
Genom is on a distinguished road (10+)
Re: [2005] "A DataTable named 'Stok' already belongs to this DataSet."

for 1) Hmm but it works good exccept this
for 2) it seems that it doesnt exists after clear function but it gives the error
__________________
Dim Me As Coder
Genom is offline   Reply With Quote
Old Feb 20th, 2007, 06:36 PM   #4
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)
Re: [2005] "A DataTable named 'Stok' already belongs to this DataSet."

My question is "why remove the table in the first place". If you just call the Fill method of a DataAdapter and pass a DataSet and a table name then it will populate a DataTable with that name, creating it if it doesn't exist. If you want to get rid of existing data then just clear the contents of the table:
VB Code:
  1. If myDataSet.Tables.Contains("TableName") Then
  2.     'Remove any existing data.
  3.     myDataSet.Tables("TableName").Clear()
  4. End If
  5. 'Populate the specified table, creating if required.
  6. myDataAdapter.Fill(myDataSet, "TableName")
__________________

2007, 2008, 2009, 2010

Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET
jmcilhinney is offline   Reply With Quote
Old Feb 20th, 2007, 06:45 PM   #5
Genom
Addicted Member
 
Genom's Avatar
 
Join Date: May 06
Posts: 178
Genom is on a distinguished road (10+)
Re: [2005] "A DataTable named 'Stok' already belongs to this DataSet."

Thanks again... it worked great jmchil
__________________
Dim Me As Coder
Genom is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:15 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.