1
我得到錯誤「System.Runtime.InteropServices.InvalidComObjectException:'已從其基礎RCW分離的COM對象不能使用。只有當我在using
塊執行OleDbCommand
對象與parameters
OleDbCommand在使用塊:已經從其基礎RCW分離的COM對象不能使用
using (OleDbCommand comm = new OleDbCommand())
{
comm.Connection = conn;
comm.CommandType = CommandType.Text;
string txt = "SELECT* FROM [ListForGroup] WHERE [email] = @email";
comm.Parameters.Add("@email", OleDbType.VarWChar).Value = userEmail;
comm.CommandText = txt;
conn.Open();
OleDbDataReader reader = comm.ExecuteReader();
List<ListForGroups> list = returnLists(reader);
conn.Close();
cmbSelectList.DataSource = list;
cmbSelectList.DisplayMember = "listName";
cmbSelectList.ValueMember = "listForGroupsID";
}
有誰知道原因是什麼。我可以解決它使用OleDbCommand
對象與CommandText
沒有parameters
但我讀這是個壞主意。我想在using
區塊中做到這一點,以確保所有資源都將被釋放。