![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
class Program
{
static void Main(string[] args)
{
OperateAccess();
}
public static void OperateAccess()
{
// OLE DB.NET Framework 数据提供程序使用标有问号 (?) 的定位参数,而不使用命名参数。
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sharetovm\db1.mdb;User Id=admin;Password=;";
string insertSQL = "INSERT INTO info([name],[address]) values(?,?)";
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
// The insertSQL string contains a SQL statement that
// inserts a new row in the source table.
OleDbCommand command = new OleDbCommand(insertSQL);
//access数据库用问号占位符的时候,添加的值是按问号的先后顺序的
command.Parameters.Add("@name", OleDbType.VarChar, 50, "name").Value = "Jhon";
command.Parameters.Add("@address", OleDbType.VarChar, 50, "address").Value = "China";
// Set the Connection to the new OleDbConnection.
command.Connection = connection;
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
}
}