我有一个表单,其中包含引用表的按钮并且按钮表示表。默认的按钮图像是免费的,我希望按钮图像根据数据库表中的“free”或“busy”值进行更改,并且我知道代码中存在错误。根据数据库更改按钮图像
如何让这个工作?
编辑:
我已经取代了自定义按钮的默认股票按钮现在它给什么,我检查了查询的结果,这是正确的,但没有什么变化,没有错误。
我的表如下:
| tablenum | tabestatusint |
|----------|---------------|
| 1 | 0 |
| 2 | 1 |
| 3 | 1 |
所以,如果tabestatusint
是0
应该改变形象
这是我曾尝试:
public void checkSuites()
{
Dictionary<int, Control> btnList = new Dictionary<int, Control>();
btnList.Add(1, Button1);
btnList.Add(2, Button2);
SqlCommand checkSuite = new SqlCommand(
"SELECT tablestatusint FROM tablesstatustbl", cn);
SqlDataReader readSuite = checkSuite.ExecuteReader();
while (readSuite.Read())
{
int suiteIndex = Convert.ToInt32(readSuite["tblstatusint"]);
string suitePath = "tblstatusint" + suiteIndex;
foreach (Button key in btnList.Values)
{
if (key.Name == suitePath)
{
key.Image = My_Café_Manger.Properties.Resources.tablesbusy;
}
}
}
}
当应用程序崩溃时,您应该在事件日志中获取堆栈跟踪。请在您的问题中包含该堆栈跟踪。 –
名称'btnList'与它的类型不是很相关 – dcg
@Renato Parreira你能帮我解决这个问题吗 –