473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate 2 or more datagrids from one OleDBCommand

Hi All,

I wish to populate more than one datagrid from the same OleDBCommand. The
code I have is:

Dim objCmd As New OleDbCommand(st rSql, objConn)

Then...

Me.dgTariffHoli dayHomesBand1.D ataSource = objCmd.ExecuteR eader()
Me.dgTariffHoli dayHomesBand1.V isible = True
Me.dgTariffHoli dayHomesBand2.D ataSource = objCmd.ExecuteR eader()
Me.dgTariffHoli dayHomesBand2.V isible = True

I get this error when the second call to objCmd.ExecuteR eader() is called:
System.InvalidO perationExcepti on: ExecuteReader requires an open and
available Connection.

The reason for populating multiple grids from the same data, is that I am
calling ALL columns in the SQL, and then using (for example) columns A and
B
in DG1, C and D in DG2...and so on.

Surely I don't need a new recordset for each datagrid???

Simon.
Nov 19 '05 #1
1 2027
There are a couple problems with your approach.

First, the ExecuteReader method requires that you close and re-open the
connection, just as the code implies but you can't use a DataReader as the
DataSource for a DataGrid. You need something that implements IList or
IListSource. You can research both of those interfaces in the MSDN Library
to see what classes implement them.

Another problem is that you're making two queries to the database and
populating the DataGrids sequentially. What happens if the data changes
between calls? You can't be sure the data in the DataGrids will match.
What you need to do is get the data once, using a DataSet or even a
DataTable and set both DataGrids to use the same DataSource.

Hope this helps,

DalePres
MCAD, MCSE, MCDBA
"Simon Harris" <to***********@ makes-you-fat.com> wrote in message
news:OD******** ******@TK2MSFTN GP11.phx.gbl...
Hi All,

I wish to populate more than one datagrid from the same OleDBCommand. The
code I have is:

Dim objCmd As New OleDbCommand(st rSql, objConn)

Then...

Me.dgTariffHoli dayHomesBand1.D ataSource = objCmd.ExecuteR eader()
Me.dgTariffHoli dayHomesBand1.V isible = True
Me.dgTariffHoli dayHomesBand2.D ataSource = objCmd.ExecuteR eader()
Me.dgTariffHoli dayHomesBand2.V isible = True

I get this error when the second call to objCmd.ExecuteR eader() is called:
System.InvalidO perationExcepti on: ExecuteReader requires an open and
available Connection.

The reason for populating multiple grids from the same data, is that I am
calling ALL columns in the SQL, and then using (for example) columns A and
B
in DG1, C and D in DG2...and so on.

Surely I don't need a new recordset for each datagrid???

Simon.

Nov 19 '05 #2

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

Similar topics

7
6226
by: mp | last post by:
No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required...
0
885
by: Alper AKCAYOZ | last post by:
Hello, I am developping an application which receives some double-type values from two different socket by two threads. Thread_A receives from Socket_A and Thread_B receives from Socket_B in loops I display the values received from Socket_B in 3 datagrids. All DataGrids have 4 colums that are "Order", "Name", "Value" and "Unit". I put the...
2
1353
by: Rui Macdonald | last post by:
What is wrong with this code to populate a DropDownList? Can somebody Help me? Tnx RMac ===================================================================================== WebForm.aspx.vb
1
2019
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da browsers and click update it gave me this error: Specified argument was out of the range of valid values. Parameter name:
3
1965
by: Jerry | last post by:
Hello everyone! I'm trying to populate a dropdown list from SQL Server but it's not being populated. I've tried all sorts of suggestions and examples that I found from Google but I just can not get it to work. I am able to access the database from other pages and display a list of records, but I just can't get the data to go into the dd...
1
6514
by: MastaKay | last post by:
I hv dropdownlist on a c# page connected to a database(MS Access). I want to get values onto my datagrid when I select a value from the dropdownlist.The Item I select from the dropdown will determine what I get loaded onto the datagrid. Please help with some code. connect.ConnectionString = strng; OleDbCommand command = new...
3
1034
by: adz1809 | last post by:
Hi all, I'm have issues with my DB connection and the use of DataGrids. My DB connection is through my web.config file and the sub looks as follows: sub OpenDatabase() sysConn = ConfigurationSettings.AppSettings("SystemConnection")
0
4576
by: AxleWacl | last post by:
Hi, The below error is what I am receiving. The code im using is below the error, for the life of me, I can not see where any parameter is missing..... Server Error in '/FleetcubeNews' Application. -------------------------------------------------------------------------------- No value given for one or more required parameters. ...
1
2016
by: Tarik Monem | last post by:
Hi everyone and I hope that you can help. I am trying to send a value of a cell within a Datagrid to my php file which has a simple sql query: here's the php: <? $server = "localhost";
0
7446
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...
0
7718
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. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
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...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
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...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
763
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...

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.