So I recently asked the following questions:
Reading A Fixed Format Text File – Part 2
Reading A Fixed Format Text File
I was finally able to read the access database by using the following code:
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();
I am attempting to leverage LINQ to DATASET by using the follow block of code:
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")
}
);
The result of the query returns no results, I should be getting thousands of results, there any fundamentally wrong with my query? There any other way I generate a result that limits the information from the DataTable?
I need to be able to provide the a query ( or some other solution ) a regular expression that matches the “NAME” column and only get several results. I am going to attempt to use ability for a regular expression to Match ( which is a boolean statement ) against each Name.
You have not initialized
MyDataTableby a data after instantiation, you have filled in data set but not a data table. So just try outMyDataSet.Tables[0]instead ofMyDataTable.AsEnumerable()