0

I have a class that I am using below. And I am using this class for my windows application. However, when I call the method from my application ReadInConfig() it successfully reads and fills the datatable, and assigns the _sip_ip address.

In my windows application I have the following. However, it doesn't give me the sip_ip that it has been assigned.

ConfigSIP readIn = new ConfigSIP();
readIn.ReadInConfig();
string sip_ip = readIn.sip_ip(); // Get nothing here.

I am thinking as the _sip_ip that has been assigned by the data table is a different object than doing this readIn.sip_ip();

Is there any way I can solve this problem?

Many thanks,

public class ConfigSIP
{
    private string _sip_ip;

        // Fill the data table and assign the sip ip.
    public void ReadInConfig()
    {
        DataTable dt = new DataTable("Admin");
        dt.ReadXmlSchema(@"C:\Config.xml");
        dt.ReadXml(@"C:\Config.xml");

        _sip_ip = dt.Rows[0]["Sip_ip"].ToString();
    }

        // Return the sip ip address.
    public string sip_ip()
    {
        return _sip_ip;
    }
}
2
  • What is "nothing"? An empty string? If so, this is a perfectly valid value for the _sip_ip field. If it is not a valid value, then put an assertion right after assigning it, which states so. Commented Apr 20, 2009 at 15:12
  • NOTE the OP edited the missing line into the question as it was being answered. Commented Feb 6, 2012 at 11:41

2 Answers 2

6

You forgot to call ReadInConfig:

ConfigSIP readIn = new ConfigSIP();
readIn.ReadInConfig();
string sip_ip = readIn.sip_ip();
Sign up to request clarification or add additional context in comments.

2 Comments

Hello, sorry. I was calling ReadInConfig(). when I copied and pasted I must have left it out. I have now edited my code.
In that case my guess is that dt.Rows[0]["Sip_ip"].ToString() is empty. Try setting a breakpoint at that line and see what your datatable contains.
3

If your code is copied verbatim your client code isn't calling the ReadInConfig() method. So the string will never get populated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.