Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2004, 04:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default HELP - C# newbie question on variables & propertie

I have a class that is access a webservice that contains the stored
procedure that I am accessing but I do not know how to apply variables to the elements of the dataset so that I can access it in my property.
ANY help or direction would be appreciated. Thanks.

[u]Here is my class code</u>:

public class InvoiceList
{
private int iintClientid = 0;
private int iintMonth = 0;
private int iintYear = 0;
private string istrFullName;
private DataSet idsInvoices;
private string dsReturnedData = "ClientInvoices";

// Constructor
public InvoiceList(int aintClientID, int aintMonthText, int aintYearText)
{
iintClientid = aintClientID;
iintMonth = aintMonthText;
iintYear = aintYearText;

// Connect to the PSSBilling_WebService.
PSSBilling.Service1 wsSearch = new PSSBilling.Service1();

// Define the dataset for this class.
idsInvoices = new DataSet();
idsInvoices = wsSearch.getInvoiceDataByClient( intClientid, iintMonth,
iintYear );

istrFullName =
Convert.ToString(idsInvoices.Tables["ClientInvoices"].Columns["full_name"].ColumnMapping["full_name"]);
Console.WriteLine(istrFullName);
}

[u]Here is my PROPERTY CODE</u>:

//Public Property created to EXPOSE the data elements for the INVOICE
FORM.

public string InvoiceFullName
{
get
{
return istrFullName; // THIS IS TELLING ME UNREACHABLE CODE
Console.WriteLine(istrFullName);
}
}
}
 
Old February 4th, 2004, 07:14 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I can't see anything wrong with this. Can you post the exact error?
 
Old February 4th, 2004, 07:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

As soon as return is found in a method (in this case, the Get accessor for the InvoiceFullName property), the return value is returned, and execution of the method stops:
Code:
get
{
  return istrFullName;
  // THIS IS TELLING ME UNREACHABLE CODE
  Console.WriteLine(istrFullName);
}
As you can see, the Console.WriteLine call occurs after the return statement and is therefore unreachable. Swap the two statements and you should be fine:
Code:
get
{
  Console.WriteLine(istrFullName);
  return istrFullName;
}
Not sure about the other problems you're having though. Can you elaborate a bit?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 5th, 2004, 08:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

In my class, I am trying to verify the VALUE in this field called "Full_Name" but I am getting back the FIELD NAME, "Full_Name" not the value in it. Should I not see the value with the parameters I have setup for this variable = (istrFullName =
Convert.ToString(idsInvoices.Tables["ClientInvoices"].Columns["full_name"].ColumnMapping["full_name"]);
?

In my PROPERTY I get nothing back in the Console.Writeline command.

Thank you guys for your time and help. If you can lend any more suggestions they would be appreciated.
 
Old February 5th, 2004, 10:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

A colleague of mine helped by stating that I had defined the ROW and that is why the value was not showing up. Here is what I did:

istrFullName = Convert.ToString(idsInvoices.Tables["ClientInvoices"].Rows[1]["full_name"]);

I did not realize I had to DEFINE the row that I was looking at.

Thank you guys again for your time and help. If you have any comments, suggestions or direction it would be appreciated.
 
Old February 5th, 2004, 10:12 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

This code will return the name from the second row in the table in the dataset. The index are zero based, so Row[1] means the second row.

You can think of the Table in a DataSet like a normal table, or a spread sheet. It's divided in Rows and Columns:
Code:
DataTable myTable = idsInvoices.Tables["ClientInvoices"]

FullName = myTable.Rows[0]["FullName"].ToString() // returns FullName of first record
FullName = myTable.Rows[1]["FullName"].ToString() // returns FullName of second record
AnotherValue = myTable.Rows[0][0].ToString() // returns the first column for the first record
Take a look here: http://msdn.microsoft.com/library/de...gdatatable.asp and the articles around this one for more info.

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 6th, 2004, 03:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks for the help. It is appreciated.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie question peterh Classic ASP Databases 3 January 17th, 2008 12:25 PM
Newbie question savoym JSP Basics 1 August 16th, 2006 03:15 AM
Newbie: XSLT & Scripts kwilliams XSLT 13 August 5th, 2005 11:39 AM
Newbie...probably a simple question...variables IP076 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 November 30th, 2004 03:24 PM
Newbie question maccer88 Access 1 October 18th, 2003 05:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.