C#表适配器更新不起作用

时间:2008-11-29 05:09:47

标签: c# database sql-server-ce tableadapter

我正在尝试将对象序列化为sql compact数据库。我正在使用VCS Express 2008.每次运行测试以查看我的数据是否都发送到数据库时,数据库中没有任何内容。我的代码:

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();
                }

它编译得很好,但由于某种原因不起作用。

1 个答案:

答案 0 :(得分:0)

您必须调用适配器更新方法以及DataSet上的AcceptChanges