我想访问Load
事件中TextBox.TextChanged
事件中创建的获取数据。
我该怎么做?
private void Login_Load(object sender, EventArgs e)
{
//Instantiating DB Obj
DataBaseConnection obtainData = new DataBaseConnection();
//Filling dataset
obtainData.passSqlCmdandFillDs = "select * from [tblLogin]";
}
private void txtDisplay_TextChanged(object sender, EventArgs e)
{
//Want to user obtainData here
}
答案 0 :(得分:1)
在obtainData
事件之外声明Login_Load
,以便其他方法可用。
DataBaseConnection obtainData;
private void Login_Load(object sender, EventArgs e)
{
//Instantiating DB Obj
obtainData = new DataBaseConnection();
//Filling dataset
obtainData.passSqlCmdandFillDs = "select * from [tblLogin]";
}
private void txtDisplay_TextChanged(object sender, EventArgs e)
{
if (obtainData != null)
{
// Use obtainData here
}
}