Solved

Multiple SQL queries in a Gridview

Posted on 2008-06-19
7
1,181 Views
Last Modified: 2011-08-03
Currently I am displaying information gathered from several database tables in a gridview. Most of this can be achieved by subqueries.

However, a few columns that I would like to display have results that can contain more then one value from a certain table. Is there a possiblity to run a second sql query for a specific itemtemplate / boundField in a gridview?
0
Comment
Question by:inghfs
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:OMC2000
ID: 21821486
you could add processing of RowDataBound event to you class and at that moment execute another SQL query and build value for some specific cell text
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 21821500
0
 

Author Comment

by:inghfs
ID: 21822514
Ok i tried to use the msdn code, and on the rowDataBound event I keep getting the error:

"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."

Any idea?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 15

Expert Comment

by:OMC2000
ID: 21823159
As far as I understand .NET does not allow opening of several MS SQL cursors simultaneously. So, you should set SQL Query for your GridView as DataSourceId property and asp:SqlDataSource with SQL statement defined for it. Then it makes DataSet as disconnected recordset and this way frees resources for another SQL statement to be executed on RowDataBound.
And dont forget to close connection each time in RowDataBound.
0
 

Author Comment

by:inghfs
ID: 21829209
ok, it is working so far, thanks.
But how can I use a value from the gridview (let's say ID) for the query of the rowdatabound?
0
 
LVL 15

Accepted Solution

by:
OMC2000 earned 500 total points
ID: 21829292
     protected void MyDG_RowDataBound(object sender, GridViewRowEventArgs e)
      {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
-- you can get value of some column in the way like the following:
            int status_id =
               Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,    "status_id"));

-- you can get grid key value in the way like the following:
            string mykey = string.Empty;
           
                GridView g =(GridView)sender;
           
                mykey = g.DataKeys[e.Row.RowIndex].Value.ToString();
...

0
 

Author Closing Comment

by:inghfs
ID: 31468711
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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