473,698 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filling two datagrids from two SELECTS in one DataSet

This code has two SELECT statements, each returning several records. I want
to fill a dataset and then two datagrids. How would I fill the SECOND
datagrid from this code
-----

Sub BindSQL()
Dim MyConnection As SqlConnection
Dim DS as DataSet
Dim MyCommand As SqlDataAdapter
Dim RcdCount As Integer

'Our SQL string
Dim sqlStr As String = "SELECT title FROM authors SELECT au_lname FROM
authors"

'The connection to our database
Dim strConn As String = "server=(local) ;uid=sa;pwd=;" & _
"database=pubs; Trusted_Connect ion=yes;"

Next we need to instantiate our connection and command object, and the fill
our DataSet object with the results of the SQL query:
...

'Open up our connection with our connection object
MyConnection = New SQLConnection(s trConn)

'To execute our Sql Statement and provide our active connection
MyCommand = NewSqlDataAdapt er(sqlStr, MyConnection)

'Create instance of DataSet object and fill our predetermined
'datagrid with it and we name it
DS = new DataSet()
MyCommand.Fill( DS, "pubs")

--
_____
DC G
Nov 18 '05 #1
2 1362
Hi,
You can use Tables collection of the dataset.
"DC Gringo" <dc******@visio ntechnology.net > wrote in message
news:O4******** ******@TK2MSFTN GP09.phx.gbl...
This code has two SELECT statements, each returning several records. I want to fill a dataset and then two datagrids. How would I fill the SECOND
datagrid from this code
-----

Sub BindSQL()
Dim MyConnection As SqlConnection
Dim DS as DataSet
Dim MyCommand As SqlDataAdapter
Dim RcdCount As Integer

'Our SQL string
Dim sqlStr As String = "SELECT title FROM authors SELECT au_lname FROM
authors"

'The connection to our database
Dim strConn As String = "server=(local) ;uid=sa;pwd=;" & _
"database=pubs; Trusted_Connect ion=yes;"

Next we need to instantiate our connection and command object, and the fill our DataSet object with the results of the SQL query:
...

'Open up our connection with our connection object
MyConnection = New SQLConnection(s trConn)

'To execute our Sql Statement and provide our active connection
MyCommand = NewSqlDataAdapt er(sqlStr, MyConnection)

'Create instance of DataSet object and fill our predetermined
'datagrid with it and we name it
DS = new DataSet()
MyCommand.Fill( DS, "pubs")

--
_____
DC G

Nov 18 '05 #2
You have to have 2 datatables in the dataset to do what you want

When you do this.
MyCommand.Fill (DS, "pubs"

even if you have 2 queries ADO.NET will merge the result sets into one Datatable

So what you have to do is execute the fill command one at a time for each select queries that you have. Also use different table names in the Fill method call (i.e. "pubs1", "pubs2", etc)

Then bind the 2 datatables seperately to your datagrids

Suresh
----- DC Gringo wrote: ----

This code has two SELECT statements, each returning several records. I wan
to fill a dataset and then two datagrids. How would I fill the SECON
datagrid from this cod
----

Sub BindSQL(
Dim MyConnection As SqlConnectio
Dim DS as DataSe
Dim MyCommand As SqlDataAdapte
Dim RcdCount As Intege

'Our SQL strin
Dim sqlStr As String = "SELECT title FROM authors SELECT au_lname FRO
authors

'The connection to our databas
Dim strConn As String = "server=(local) ;uid=sa;pwd=;" &
"database=pubs; Trusted_Connect ion=yes;

Next we need to instantiate our connection and command object, and the fil
our DataSet object with the results of the SQL query
..

'Open up our connection with our connection objec
MyConnection = New SQLConnection(s trConn

'To execute our Sql Statement and provide our active connectio
MyCommand = NewSqlDataAdapt er(sqlStr, MyConnection

'Create instance of DataSet object and fill our predetermine
'datagrid with it and we name i
DS = new DataSet(
MyCommand.Fill( DS, "pubs"

--
____
DC

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2204
by: Krzysztof Karnicki | last post by:
I have such a problem… I have create my custom DataGridColumn inheriting from System.Windows.Forms.DataGridColumnStyle on using it on DataGrid, to show rows painted by me self. Because dates taken from database are very large, and filling DataSet bounded to this DataGrid takes some time, a decided to put fill logic into new thread. And so method running in this thread clears only this DataSet bounded to DataGrid and fills it once more...
0
948
by: Dave | last post by:
Hi Have Master/Detail relationship within 2 datagrids. Binding works fine, when a user selects a row in the Master grid it updates the display in the detail grid, awesome...........but.. I also have a combobox on the form, when a user selects a value it filters the Master grid, my problem is, if there are no rows displayed in the Master it still shows records in the Details Grid of the last selected row.
0
1059
by: AMeador | last post by:
I am new to writing apps that use a database in general and in .NET. I have read about how to use SqlCommands and executing strait SQL for inserts, selects, etc... I have also read about datasets & dataviews. My question need here is for information on how/when to utilize these different methods when it comes to dealing with the information that a user enters on a windows form. Is it preferable to use a dataview and bind the controls to...
3
2000
by: crjunk | last post by:
I have a 3 table in my DataSet that I'm filling with data. After I've filled these 3 tables, I'm then trying to run a query that will fill a 4th table in the DataSet with data from the three tables that are already pouplated. When my code tries to fill the 4th table, ReportData, I receive the following error message: Invalid object name 'tmpPROJECTINFO'. Invalid object name 'tmpContacts'. Invalid object name 'tmpRECEIVEREC'. Can...
0
1253
by: Scott Meddows | last post by:
I'm having trouble scrolling some datagrids so they sync up... I have two identical datagrids on a form, filled with eh same dataset. I want a user to be able to scroll on the datasets and the other dataset then scrolls to the same place on the other dataset (bare with me). This is the code that I have so far... Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load...
9
1267
by: Dave | last post by:
Apologies if this has come up before, but I can't find it if it has. I am fairly new to .Net and am having problems with ghosts in the datagrid. Basically I have a find screen that accepts search criteria, then interrogates a database to find all matching records. These are put into a dataset, which has a dataview that is used as the datasource of my datagrid, which is read only. The idea is that the user selects which record they...
4
1176
by: mark | last post by:
(windows app not web) I have a procedure to populate a given datagrid (Datagrid1) with a dataset from an indexed data connection. It works: Globals: Dim FileName1 As String Dim DS As System.Data.DataSet Dim OleDbConnection1(20) As System.Data.OleDb.OleDbConnection Dim OleDbDataAdapter1(20) As System.Data.OleDb.OleDbDataAdapter Dim CurrentIndex As Integer = 0
7
1845
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table in a different dataset. One combo box is displaying the Employees payroll ID. The other is
0
1080
by: Jim | last post by:
OK here's my disclaimer: I'm very new to ASP.NET and posting on Google Groups, so please bear with me and feel free to correct either the way I code or the way I post. I have an ASP.NET page that is driven off of a dynamic dropdownlist control. In the page_load sub, I make the DB connection and fill the list based on a table of employees. Once an employee is selected, there are various datagrids below that are populated based on that...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.