我是数据库的新手,我正面临着障碍。我在尝试更新数据库时遇到错误。
另请注意,我的数据库是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();
}
此代码的大纲来自另一个问题的答案,我正在尝试对其进行测试并使其正常工作。谢谢!