2013-10-08 23 views
0

我有一個Windows窗體應用程序,其中我使用ms訪問數據庫來檢索值。字符串值不附加到Windows中的文本框

現在根據我的Load事件需要,我必須從ms訪問數據庫檢索的值中填充文本框,但將字符串值設置爲文本框時,它將變空。

這裏是我的代碼..

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

回答

0

我想你的問題是,你實際上並沒有填充文本框,而是你用文本框的文本填充串!

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

那現在應該填充他們

0

你不填充你把它們的值到一個變量文本框。 變化:

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

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

希望這有助於。