Question

I have a windows form application in which I am using ms access database to retrieve values.

Now as per my need on Load event I have to populate the textbox from the values retrieved from ms access database but while setting the string value to textbox it is coming empty.

Here is my code..

string ipaddress, textfileSaveLocation;
string Port;

public TechsoftIPCommunicator()
{
    InitializeComponent();
}

protected override void OnLoad(EventArgs e)
{
    OleDbConnection Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\techsoft\\PROJECTTT.mdb;Jet OLEDB:Database Password=techsoft");
    OleDbCommand cmd;
    Conn.Open();

    cmd = new OleDbCommand("Select * from IPCOMSettings", Conn);
    OleDbDataReader dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        ipaddress = dr.GetString(1);
        Port = dr.GetString(2);
        textfileSaveLocation = dr.GetString(3);
    }

    ipaddress = textBox1.Text;
    Port = textBox2.Text;
    textfileSaveLocation = textBox3.Text;
    base.OnLoad(e);
}
Was it helpful?

Solution

I assume your issue is that you are not actually populating the textboxes but instead you are populating the strings with the text of the textboxes!

 textBox1.Text = ipaddress;
 textBox2.Text = Port;
 textBox3.Text = textfileSaveLocation;

That should populate them now

OTHER TIPS

Your not populating the textboxes you are putting the value of them into a variable. Change:

    ipaddress = textBox1.Text;
    Port = textBox2.Text;
    textfileSaveLocation = textBox3.Text;

To

    textBox1.Text = ipaddress;
    textBox2.Text = Port;
    textBox3.Text = textfileSaveLocation;

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top