Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

accessing data in strongly typed datasets using stored proc and VS2005 dataset designer

Posted on 2006-06-06
9
Medium Priority
?
276 Views
Last Modified: 2010-04-16
I have created a dataset through the report designer in VS2005.  I am able to instantiate the dataset and get the data into the table just fine.  However, now I'm trying to reference the data in the table and am having troubles getting the syntax right.

The GetReportParameterInfo method below is called from the getReportParameterInfo method below...I can see through debugger that my data is getting back to the calling method but I can't figure out the syntax to get the data out of each column.  The strongly typed part of referencing by .notation of the column name doesn't seem to be an option when I get back there as the columns are not available in the drop down so than I tried putting the column name in a string.  I also wanted to see if I could access the columns from the called method by

public void getReportParameterInfo()
        {
            DataServices.ReportGeneration objReportGeneration = new DataServices.ReportGeneration();
            DataSet dsParameterInfo;

            dsParameterInfo = objReportGeneration.GetReportParameterInfo(38);
           
            //trying to get the data from the columns now...this is not working but I know my data is in the dataset. This
//brings back null.
            string strParmCtrl = dsParameterInfo.Tables[0].Columns["parm_ctrl"].ToString();

        }


public DataSet GetReportParameterInfo(int ReportCd)
        {
            ReportParameterDataset ds = new ReportParameterDataset();

            try
            {
                AdoHelper ah = new AdoHelper("ABS");
                ah.FillDataset("abs_s_GetReportData", ds,
                        new string[] { ds.abs_s_GetReportData.ToString() }, ReportCd);

//THIS IS MY TRY AT GETTING COLUMN DATA in the Called method.  It doesn't really do me any good as I need it in
//the calling method but I wanted to see at what point I could reference it like a strongly typed datset. This does not work
//The dropdowns allow me to enter this however when compiled it errors with the error :
'...ReportParameterDataset.abs_s_GetReportDataDataTable' is a 'type', which is not valid in the given context'

                      string strTextlbl;
                    strTextlbl = ReportParameterDataset.abs_s_GetReportDataDataTable[0].parm_textlbl.ToString();
               

            }
           

            catch (Exception e)
            {
                throw new Exception("blah blah blah", e);
            }

            return ds;
        }

THANK YOU!!!!
0
Comment
Question by:babybird
  • 5
  • 4
9 Comments
 
LVL 25

Expert Comment

by:dstanley9
ID: 16843773
abs_s_GetReportDataDataTable is probably the type created to define the abs_s_GetReportData table.  try:

strTextlbl = ReportParameterDataset.tableabs_s_GetReportData.parm_textlbl.ToString();
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16843800
Check that, it should be:

strTextlbl = ds.tableabs_s_GetReportData.parm_textlbl.ToString();

Keep in mind that "tableabs_s_GetReportData" was a guess based on the default dataset generation naming.  Use intellisense to find the proper name of the table instance.
0
 

Author Comment

by:babybird
ID: 16844107
Well, I seem to do a really good job of getting the column name but not the value in the column...

This is what I have now:
 strTextlbl = ds.abs_s_GetReportData.parm_textlblColumn.ToString();

I can see my data in abs_s_GetReportdata but the value of this is the column name 'textlbl' instead of what is in textlbl column.

Ughhhh!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:babybird
ID: 16844155
This also brings me back the column name rather than the data in the column:
strTextlbl = ds.Tables[0].Columns[0].ToString();
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16844172
That's because parm_textlblColumn is the type of the column itself, not the data within the column.  Try using "parm_textlbl" instead of "parm_textlblColumn".
0
 

Author Comment

by:babybird
ID: 16844203
it isn't in the intellisense as an option.
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 1000 total points
ID: 16844217
Sorry; Ive forgot this whole time that you need a row to work with:


The non-strongly-typed method would be:

strTextlbl = ds.Tables[0].Rows[0]["parm_textlbl"].ToString();

the strongly-typed version would be something like:

ReportParameterDataset.abs_s_GetReportDataRow row = ds.tableabs_s_GetReportData.Rows[0] as ReportParameterDataset.abs_s_GetReportDataRow;

strTextlbl = row.parm_textlbl.ToString();
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16844232
OR you can loop through all of the rows:

foreach (ReportParameterDataset.abs_s_GetReportDataRow row in ds.tableabs_s_GetReportData)
{
  strTextlbl = row.parm_textlbl.ToString();
}
0
 

Author Comment

by:babybird
ID: 16844310
Excellent! That worked! Thank you so much!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

564 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