【发布时间】:2012-02-26 02:48:36
【问题描述】:
所以我最近问了以下问题:
Reading A Fixed Format Text File - Part 2
Reading A Fixed Format Text File
我终于可以使用以下代码读取访问数据库了:
string DATABASE_PROVIDER = "Provider=Microsoft.ACE.OLEDB.12.0";
string CVS Application.StartupPath + ""\\Database.accdb";
string DATA_SOURCE = "Data Source" + CVS;
string connectionString = DATABASE_PROVIDER + DATA_SOURCE;
string TABLE = " FROM STUFF";
string SELECT = "SELECT CODE, NAME, ICON, FUNCTION;
string StringQueryCmd = SELECT + TABLE;
OleDbConnection MyConnection = new OleDbConnection(connectionString);
OleDbCommand Command = OleDbCommand(StringQueryCmd,MyConnection);
OleDbAdapter MyDataAdapter = new OleDbAdapter(Command);
DataSet MyDataSet = new DataSet();
DataTable MyDataTable = new DataTable();
MyConnection.Open();
MyDataAdapter.Fill(MyDataSet,"STUFF");
MyConnection.Close();
我正在尝试通过使用以下代码块来利用 LINQ to DATASET:
var query = (
from order in MyDataTable.AsEnumerable()
where order.Field<int>("CODE") >= 41
select new
{
CODE = order.Field<int>("CODE"),
NAME = order.Field<string>("NAME"),
ICON = order.Field<string>("ICON"),
FUNCTION = order.Field<string>("FUNCTION")
}
);
查询结果没有返回结果,我应该得到数千个结果,我的查询有什么根本错误吗?还有其他方法可以生成限制来自 DataTable 的信息的结果吗?
我需要能够为查询(或其他解决方案)提供与“NAME”列匹配的正则表达式,并且只能得到几个结果。我将尝试使用正则表达式的能力来匹配每个名称(这是一个布尔语句)。
【问题讨论】:
标签: c# linq c#-4.0 dataset oledb