Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Vb.Net - Adding Data to DataTable

Posted on 2013-01-08
4
Medium Priority
?
255 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
[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
  • 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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