Solved

Multiple SQL queries in a Gridview

Posted on 2008-06-19
7
1,175 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

18 Experts available now in Live!

Get 1:1 Help Now