下面是我的跟蹤志願者的計劃。我的問題是,在下面的兩個函數中,當調用fillListBoxData()
時,大約一半的時間跳轉到fillDataGridView
函數。在第15行,dataAda1.Fill(datTab3);
程序立即跳轉到fillDataGridView(string fullName)
。我不知道爲什麼。我的代碼跳到一個函數,當它不應該是
有人可以幫助我,並讓這個程序停止這樣做。
public void fillListBoxData()
{
//Open connection
//found in app.config
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.Database1ConnectionString))//database ONE
{
//open the connection
conn.Open();
// Create new DataAdapter
using (SqlDataAdapter dataAda1 = new SqlDataAdapter("SELECT (firstName + ' ' + lastName) AS NAME FROM dbo.VolunteerContactInfo", conn))
{
// Use DataAdapter to fill DataTable
DataTable datTab3 = new DataTable();
dataAda1.Fill(datTab3);
//assign the dataTable as the dataSource for the listbox
volList.DataSource = datTab3;
//display member needed to show text
volList.DisplayMember = "NAME";
conn.Close();
}
}
}
void fillDataGridView(string fullName)
{
string tableName = "dbo." + fullName;
// Open connection
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.Database2ConnectionString))//database TWO
{
//open the connection
conn.Open();
// Create new DataAdapter
using (SqlDataAdapter dataAda = new SqlDataAdapter("SELECT * FROM " + @tableName, conn))
{
// Use DataAdapter to fill DataTable
DataTable datTab = new DataTable();
dataAda.Fill(datTab);
volWorkDataGrid.DataSource = datTab;
}
conn.Close();
}
}
你怎麼知道它跳到'fillDataGridView'? – Kevin
您的方法'fillDataGridView'可能被註冊爲您的網格的事件處理程序,並且在填充過程中被網格調用。您需要刪除該事件處理程序以防止它被調用。 –
也可能在調試時調試程序在線程間跳轉。 –