根據您的需要,您也可以考慮Sql CE。我敢肯定,如果你指定了你正在考慮使用的數據庫,或者你的需求,如果你有用,你會得到適當和真實的連接字符串等例子。
編輯:這是SqlCe/Sql Compact
public void ConnectListAndSaveSQLCompactExample()
{
// Create a connection to the file datafile.sdf in the program folder
string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\datafile.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 test_table", 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[] { "New row added by code" });
// Save data back to the databasefile
adapter.Update(data);
// Close
connection.Close();
}
記住要添加一個引用System.Data.SqlServerCe
你連接了什麼類型的數據庫? – ddc0660 2009-07-13 20:45:46
我正在考慮使用本地.sdf文件 – Aviatrix 2009-07-13 20:51:21
已更新我的回答,以迴應您使用.sdf(Sql Ce/Sql Compact)的詳細說明 – 2009-07-14 10:57:07