Solved

Multiple SQL queries in a Gridview

Posted on 2008-06-19
7
1,182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Will we ever be able to build mobile apps in it 6 27
Need help with another query 10 36
"lblTime is not declared" 3 29
Validation for a field in asp.net 3 10
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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…

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