I'm trying to pull data from an Access database using dapper. I have the following class defined to use the fields from the access database that I need to read. I then tried to pull the data using the code below. When I run this only blanks come back. The number of blanks match the number of records in the data table.
I tried to use a shorter sql string with the same results.
I can't find any information on this issue, does anyone have any ideas about this?
public class DLabResults
{
public int ResultsFolderNumber { get; set; }
public int Request { get; set; }
public int Release { get; set; }
public string Formulation { get; set; }
public string Container { get; set; }
public string Closure { get; set; }
public string Shipper { get; set; }
// public string Label_Back { get; set; }
// public string Label_Front { get; set; }
public string FilePath { get; set; }
}
public void LoadDapperDLabResults(List<DLabResults> items)
{
string sql = "";
//sql = "SELECT tblResults_Results.R_Project_Assignment, tblResults_Results.R_Project_Request, tblResults_Results.R_Project_Release, tblResults_Results.R_Formulation, tblResults_Results.R_Closure, tblResults_Results.R_Container, tblResults_Results.R_Shipper, '' AS Blank1, '' AS Blank2, tblResults_Results.R_Test_FullPath FROM tblResults_Results WHERE(((tblResults_Results.R_Formulation)Like '*' & [Formulation] & '*') AND ((tblResults_Results.R_Closure)Like '*' & [Closure] & '*') AND((tblResults_Results.R_Container)Like '*' & [Container] & '*') AND((tblResults_Results.R_Shipper)Like '*' & [Shipper] & '*')) ORDER BY tblResults_Results.R_Project_Assignment, tblResults_Results.R_Project_Request, tblResults_Results.R_Project_Release;";
sql = "SELECT * FROM tblResults_Results";
using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\DavidsoJ\\Desktop\\Fixed Push Workbooks\\Redesigned Databases\\Development Lab Results Database.accdb"))
{
//var TM2 = connection.Query<DLabResults>(sql).ToList();
List<DLabResults> TM2 = connection.Query<DLabResults>(sql).ToList();
//add items to employess
if (items == null || items.Count < 1)
{
}
else
{
TM2.AddRange(items);
}
dataGridView1.DataSource = TM2;
}
}
The column names from the SQL query do not seem to match up with the properties of the desired object model DLabResults.
Either update the columns names returned from the query to match the object
SELECT tblResults_Results.R_Project_Request AS Request
/*, ... code removed for brevity */
FROM tblResults_Results
OR update the DLabResults property names to match the column names returned from the query
public class DLabResults {
public int R_Project_Request{ get; set; }
//... code removed for brevity
}
Either way, when using dapper the column names need to be mapped to object members in order for dapper to populate them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With