p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   HELP - C# newbie question on variables & propertie (http://p2p.wrox.com/showthread.php?t=8967)

savoym February 4th, 2004 04:17 PM

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);
}
}
}

planoie February 4th, 2004 07:14 PM

I can't see anything wrong with this. Can you post the exact error?

Imar February 4th, 2004 07:27 PM

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.

savoym February 5th, 2004 08:20 AM

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.

savoym February 5th, 2004 10:02 AM

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.

Imar February 5th, 2004 10:12 AM

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.

savoym February 6th, 2004 03:52 PM

Thanks for the help. It is appreciated.


All times are GMT -4. The time now is 11:30 PM.

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