문제

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);
}
도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top