473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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(strSql, objConn)

Then...

Me.dgTariffHolidayHomesBand1.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand1.Visible = True
Me.dgTariffHolidayHomesBand2.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand2.Visible = True

I get this error when the second call to objCmd.ExecuteReader() is called:
System.InvalidOperationException: 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 2018
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**************@TK2MSFTNGP11.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(strSql, objConn)

Then...

Me.dgTariffHolidayHomesBand1.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand1.Visible = True
Me.dgTariffHolidayHomesBand2.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand2.Visible = True

I get this error when the second call to objCmd.ExecuteReader() is called:
System.InvalidOperationException: 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
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...
0
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...
2
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
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...
3
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...
1
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...
3
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 =...
0
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'...
1
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.