字符串值不会追加到 Windows 窗体中的文本框
本文关键字:窗体 文本 Windows 追加 字符串 | 更新日期: 2023-09-27 18:34:19
我有一个Windows表单应用程序,我正在使用ms访问数据库来检索值。
现在,根据我对加载事件的需要,我必须从从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);
}
我假设您的问题是您实际上并没有填充文本框,而是用文本框的文本填充字符串!
textBox1.Text = ipaddress;
textBox2.Text = Port;
textBox3.Text = textfileSaveLocation;
现在应该填充它们
您不填充文本框,而是将它们的值放入变量中。改变:
ipaddress = textBox1.Text;
Port = textBox2.Text;
textfileSaveLocation = textBox3.Text;
自
textBox1.Text = ipaddress;
textBox2.Text = Port;
textBox3.Text = textfileSaveLocation;
希望这有帮助。