在C#中使用OLEDB可以實現(xiàn)對數(shù)據(jù)的增刪改查操作,以下是一個簡單的例子:
using System.Data.OleDb;
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\mydatabase.mdb";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
// 插入數(shù)據(jù)
string insertQuery = "INSERT INTO myTable (column1, column2) VALUES ('value1', 'value2')";
OleDbCommand insertCommand = new OleDbCommand(insertQuery, connection);
insertCommand.ExecuteNonQuery();
// 更新數(shù)據(jù)
string updateQuery = "UPDATE myTable SET column1 = 'new value' WHERE column2 = 'value2'";
OleDbCommand updateCommand = new OleDbCommand(updateQuery, connection);
updateCommand.ExecuteNonQuery();
// 刪除數(shù)據(jù)
string deleteQuery = "DELETE FROM myTable WHERE column1 = 'value1'";
OleDbCommand deleteCommand = new OleDbCommand(deleteQuery, connection);
deleteCommand.ExecuteNonQuery();
// 查詢數(shù)據(jù)
string selectQuery = "SELECT * FROM myTable";
OleDbCommand selectCommand = new OleDbCommand(selectQuery, connection);
OleDbDataReader reader = selectCommand.ExecuteReader();
while(reader.Read())
{
// 讀取數(shù)據(jù)
}
connection.Close();
以上是一個簡單的示例,實際應用中需要根據(jù)具體情況來編寫更復雜的增刪改查操作。