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
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Feb 20th, 2007, 04: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, 04:31 PM   #2
techgnome
Snarky...
 
techgnome's Avatar
 
Join Date: May 02
Posts: 15,476
techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)
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
__________________
* 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.*
* How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
* How to Use Parameters * 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, 05: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, 05:36 PM   #4
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 61,544
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-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 (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW*
jmcilhinney is online now   Reply With Quote
Old Feb 20th, 2007, 05: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
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 05:40 AM.





Acceptable Use Policy

Internet.com
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.