0
我想序列化一個對象到一個SQL壓縮數據庫。我正在使用VCS Express 2008.每次運行測試以查看數據是否發送到數據庫時,數據庫中都沒有任何內容。我的代碼:C#表適配器更新不工作
string inputForDB = null;
QuizCategoryTableAdapter quizCategoryAdapter = new QuizCategoryTableAdapter();
QuizApp._QuizApp_DataSet.QuizCategoryDataTable quizCategoryTable = new QuizApp._QuizApp_DataSet.QuizCategoryDataTable();
quizCategoryAdapter.Fill(quizCategoryTable);
//Check to see if quizCategory exists
if (quizCategoryTable.Rows.Contains(quizCategory._categoryID)) {
//overwrite (update)
//Serialize the object and put in db
MemoryStream MemStream = new MemoryStream();
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(MemStream, quizCategory);
inputForDB = Convert.ToBase64String(MemStream.ToArray());
quizCategoryAdapter.Insert(quizCategory._categoryName, quizCategory._categoryDescription, inputForDB);
//send update to database
MemStream.Close();
} else {
//append (insert)
MemoryStream MemStream2 = new MemoryStream();
IFormatter formatter2 = new BinaryFormatter();
formatter2.Serialize(MemStream2, quizCategory);
inputForDB = Convert.ToBase64String(MemStream2.ToArray());
quizCategoryAdapter.Insert(quizCategory._categoryName, quizCategory._categoryDescription, inputForDB);
MemStream2.Close();
}
它編譯得很好,但由於某種原因不起作用。
不.net 3.5的內置更新內置到tableAdapter中嗎? – jle 2008-11-29 05:51:44