Solved

Vb.Net - Adding Data to DataTable

Posted on 2013-01-08
4
251 Views
Last Modified: 2013-01-08
Good Day Experts!

I have a requirement for my project that I have not experienced before.  My experience with DataGridViews in the past have been executing a command, filling dataTable and then assigning as the DataGridView dataSource.  

Now,  I need to execute many queries and either keep filling the dataTable that populates the DataGridView or keep sending the output of each query to the DataGridView via a dataTable.

Is either of these scenarios possible? If so, do you have any recommended reading?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38756195
>Now,  I need to execute many queries and either keep filling the dataTable that populates the DataGridView

Can you elaborate? You can fill a datatable as many times as you want and grid will refresh automatically whenever datatable is changed.
0
 

Author Comment

by:Jimbo99999
ID: 38756215
MyCmd.CommandText = "Query to execute"                          
DADups.SelectCommand = MyCmd
DADups.SelectCommand.Connection = SQLConnect
DADups.SelectCommand.ExecuteNonQuery()
DADups.Fill(DTDups)

I want to do this multiple times and keep adding to the DTDups DataTable.  Then when done ading to the DataTable set it as the DataSource to the DataGridView.
Would the line "DADups.Fill(DTDups)" overwrite the previous data or just add to what was there from the previous execution?

Thanks,
jimbo99999
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 38756277
>Would the line "DADups.Fill(DTDups)" overwrite the previous data or just add to what was there from the previous execution?

No.

>DADups.SelectCommand.ExecuteNonQuery()
>DADups.Fill(DTDups)

You do not need the ExecuteNonQuery call.
0
 

Author Closing Comment

by:Jimbo99999
ID: 38756339
Excellent, works as designed.

Thanks for the insight,
jimbo99999
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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