Solved

Vb.Net - Adding Data to DataTable

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

831 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