Solved

Vb.Net - Adding Data to DataTable

Posted on 2013-01-08
4
248 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
Comment Utility
>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
Comment Utility
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
Comment Utility
>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
Comment Utility
Excellent, works as designed.

Thanks for the insight,
jimbo99999
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now