tags:

views:

155

answers:

3

Hello,

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;
    }
}
+6  A: 

You forgot to call ReadInConfig:

ConfigSIP readIn = new ConfigSIP();
readIn.ReadInConfig();
string sip_ip = readIn.sip_ip();
Jakob Christensen
Hello, sorry. I was calling ReadInConfig(). when I copied and pasted I must have left it out. I have now edited my code.
robUK
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.
Jakob Christensen
+3  A: 

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

JoshBerke
A: 

Use a Singleton.

JohnOpincar