Solved

Multiple SQL queries in a Gridview

Posted on 2008-06-19
7
1,172 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now