我不需要/不想要任何安全措施(用户名/密码等) - 我只想创建一个从 AdventureWorks“lite”数据库 (AdventureWorksLT2012_Data.mdf) 检索数据的简单示例,并将该数据存储在通用列表中.
我有以下代码来查询 MS Access 数据库。除了连接字符串和查询语句之外,它是否基本相同?
public SQLServerPOCRepository()
{
using (var conn = new OleDbConnection(
@"Provider=Microsoft.ACE.OLEDB.12.0;User ID=User;Password=Pass;Data Source=C:\SWin\DATA\SDAT42.MDB;Jet OLEDB:System database=C:\SWin\Data\wgeg.mdw"))
{
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT td_duckbill_accounts.dept_no, IIF(ISNULL(t_accounts.name),'No Name provided',t_accounts.name) AS name FROM t_accounts INNER JOIN td_duckbill_accounts ON t_accounts.account_no = td_duckbill_accounts.account_no ORDER BY td_duckbill_accounts.dept_no";
cmd.CommandType = CommandType.Text;
conn.Open();
int i = 1;
using (OleDbDataReader oleDbD8aReader = cmd.ExecuteReader())
{
while (oleDbD8aReader != null && oleDbD8aReader.Read())
{
int duckbillNum = oleDbD8aReader.GetInt16(0);
string duckbillName = oleDbD8aReader.GetString(1);
Add(new Platypus { Id = i, dbillNum = duckbillNum, Name = duckbillName });
i++;
}
}
}
}
}
该方法使用模型类Add()
的实例填充通用列表。Platypus