順序我有一個設置形式,在其在於從Access數據庫返回的數據,我想以填補形式的負載的組合框。代碼不按照源
在那裏我遇到了困難實際上是設置組合框的數據源 - 程序執行時,它填充OleDbDataAdapter的,以加載形式跳躍;跳過代碼。
這裏是我的最新代碼:
窗體加載
private void frm_settings_Load(object sender, EventArgs e)
{
Divisions divs = new Divisions();
DataSet ds = new DataSet();
ds = divs.GetActiveDivisions(); //jumps from here to loading the form
this.cmbo_divisions.DataSource = ds; //this never gets invoked
}
和各庭類
class Divisions
{
private string error;
public string Error //read only
{
get { return this.error; }
}
public DataSet GetActiveDivisions()
{
OleDbConnection conn = new OleDbConnection();
PinnacleConnection Pconn = new PinnacleConnection();
string sql = "SELECT ID, title FROM Divisions WHERE active = true;";
DataSet ds = new DataSet();
//connect to db
conn = Pconn.createConnection();
try
{
conn.Open();
}
catch (Exception ex)
{
//error handling here
this.error = ex.Message;
return ds;
}
OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn);
adapter.Fill(ds); //!!jumps from here to loading the form!!
conn.Close(); //never gets invoked?
return ds; //never gets invoked?
}
}
你可以通過我的意見看,執行跳過數據源的設置cmbo_divisions對象...導致一個空的組合框。
我很茫然,任何幫助將不勝感激。
大概拋出異常。首先,你應該在調試器中打開「停止異常」的東西,這將更容易找到這些類型的問題。此外,你可能想圍繞一個try-catch * *所有的數據庫代碼(您可能還需要一些'using'語句了。 – crashmstr
我想象你示數,並從抓 – Jonesopolis
返回空'DataSet'當我通過代碼,不執行雖然catch語句...... – wribit