有什么比 try/catch 包装更好的方法来验证 TableAdapter 上的连接是否打开或将成功打开?
public class MyItemParser
{
private myTableAdapter fa;
public FacultyParser()
{
this.fa = new facultyTableAdapter();
}
public bool HasValidConnection()
{
try
{
this.fa.Connection.Open();
}
catch(exception e)
{
return false;
}
return true;
}
public void FillList(IList<myItem> list)
{
foreach (var row in this.fa.GetData())
/**** DoSomething ****/
}
}