C# C标签文本属性在事件发生时未更改
我想将lbl_smallBlind.Text和lbl_bigbind.Text更改为从数据库检索的值。有人能告诉我为什么它不起作用吗 --我认为accessess标签属性的代码:C# C标签文本属性在事件发生时未更改,c#,winforms,C#,Winforms,我想将lbl_smallBlind.Text和lbl_bigbind.Text更改为从数据库检索的值。有人能告诉我为什么它不起作用吗 --我认为accessess标签属性的代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } public string lbl_sb_text { get { return lbl_
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string lbl_sb_text
{
get { return lbl_smallBlind.Text; }
set { lbl_smallBlind.Text = value; }
}
public string lbl_bb_text
{
get { return lbl_bigBlind.Text; }
set { lbl_bigBlind.Text = value; }
}
}
--从数据库检索值的代码:
public void rozne()
{
string constr = Properties.Settings.Default.DodgeBulletsDBConnectionString;
Form1 menuglowne = new Form1();
using (SqlCeConnection con = new SqlCeConnection(constr))
{
SqlCeCommand com = new SqlCeCommand(
"SELECT Big_blind, Small_blind FROM Site WHERE Level=1", con);
con.Open();
SqlCeDataReader reader = com.ExecuteReader();
bool hasRow = reader.Read();
if (hasRow)
{
int bb = reader.GetInt32(reader.GetOrdinal("Big_blind"));
int sb = reader.GetInt32(reader.GetOrdinal("Small_blind"));
menuglowne.lbl_sb_text = Convert.ToString(sb);
menuglowne.lbl_bb_text = Convert.ToString(bb);
}
else
{
MessageBox.Show("Coś się zjebało z importem DS.Site.");
}
}
}
lbl_sb_文本和lbl_bb_文本值设置为我想要的值,只是表单上的值不变。为什么?您无需再次创建Form1实例。因为它将为单独的对象初始化所有组件
public void rozne()
{
string constr = Properties.Settings.Default.DodgeBulletsDBConnectionString;
//Form1 menuglowne = new Form1();
using (SqlCeConnection con = new SqlCeConnection(constr))
{
SqlCeCommand com = new SqlCeCommand("SELECT Big_blind, Small_blind FROM Site WHERE Level=1", con);
con.Open();
SqlCeDataReader reader = com.ExecuteReader();
bool hasRow = reader.Read();
if (hasRow)
{
int bb = reader.GetInt32(reader.GetOrdinal("Big_blind"));
int sb = reader.GetInt32(reader.GetOrdinal("Small_blind"));
this.lbl_sb_text = Convert.ToString(sb);
this.lbl_bb_text = Convert.ToString(bb);
}
else
{
MessageBox.Show("Coś się zjebało z importem DS.Site.");
}
}
}
以下是我的建议
//Form1 menuglowne = new Form1();
this.lbl_sb_text = Convert.ToString(sb);
this.lbl_bb_text = Convert.ToString(bb);