0

我是数据库新手,遇到了障碍。尝试更新数据库时出现错误。

另请注意,如果有帮助,我的数据库是 SQL Server CE 4.0。

private void Form1_Load(object sender, EventArgs e)
{
        // Create a connection to the file datafile.sdf in the program folder
        string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\userDtbs.sdf";
        SqlCeConnection connection = new SqlCeConnection("datasource=" + dbfile);

        // Read all rows from the table test_table into a dataset (note, the adapter automatically opens the connection)
        SqlCeDataAdapter adapter = new SqlCeDataAdapter("SELECT * FROM history", connection);
        DataSet data = new DataSet();
        adapter.Fill(data);

        // Add a row to the test_table (assume that table consists of a text column)
        data.Tables[0].Rows.Add(new object[] { null, "Google", "http://www.google.com" });

        // Save data back to the databasefile
        adapter.Update(data);

        // Close 
        connection.Close();
}

此代码的大纲来自另一个问题的答案,我正在尝试对其进行测试并使其正常工作。谢谢!

4

0 回答 0