Solved

Vb.Net - Adding Data to DataTable

Posted on 2013-01-08
4
252 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 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

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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