[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Multiple SQL queries in a Gridview

Posted on 2008-06-19
7
Medium Priority
?
1,190 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 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