我正在尝试将访问数据库文件连接到我的代码,但是遇到了麻烦。当我尝试上传时,提示“无法识别的数据格式”。这是错误PyTest-Mongo documentation
的链接namespace Assignment_6
{
class Program
{
static OleDbConnection _dbConn;
//use the Northwind.accdb instance attached with the
//connecting to the Northwind.accdb, Microsoft Access database
static string _NorthwindDb_Connection = @"C:\Users\ahmed\Documents\Northwind.accdb";
static string _sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + _NorthwindDb_Connection;
static void Main(string[] args)
{
// accessing the conncetion
_dbConn = new OleDbConnection(_sConnection);
_dbConn.Open();
// Select the entities from Product table where the list price is greater than $20
string sql = @"SELECT [Product Name], [List Price]
FROM Products where [List Price] > 20
order by [List Price] DESC;";
OleDbCommand dbCmd = new OleDbCommand();
dbCmd.CommandText = sql; // using sql
dbCmd.Connection = _dbConn; // dbConn is the connection object
var dbReader = dbCmd.ExecuteReader();
// reading and printing selected entities
while (dbReader.Read())
{
Console.WriteLine("Product Name: " + dbReader["Product Name"] + " List Price: $ " + dbReader["List Price"]);
}
dbReader.Close();
_dbConn.Close();
Console.WriteLine("press enter to end");
Console.ReadLine();
}
}
}