Below is the example class of the object and .txt file, I use filehelpers to create this class,then I read a .txt file using FileHelpers and it converts this file into these objects and I put them in a List.
.txt file:
1122233
4455566
Example class:
[FixedLengthRecord(FixedMode.AllowLessChars)]
public class Example
{
[FieldFixedLength(2)]
public string first;
[FieldFixedLength(3)]
public string second;
[FieldFixedLength(2)]
public string third;
}
Reading this with filehelpers gives me 2 objects of Example.The first Example.first value being '11' etc. I push this data in a database with by converting the List to a DataTable and using SqlBulkCopy. This all goes well.
The table in the database just contains 3 columns(varchar) with column names; first,second and third.
The problem comes when I try to fetch the data back from the database and map it back into a List, I use the following code (using Dapper) for this:
IDbConnection connection = new SqlConnection(connectionString);
var rows = connection.Query<Example>("select * from examplesTable");
foreach (Example e in rows)
{
examples.Add(e); //List<Example> examples
}
This returns the correct amount of rows, however if I try to fetch data from the objects, it contains null data. I can't figure out what I'm doing wrong.
I would check that you have the data loaded correctly before the SQL bulk insert and then that you are not getting any errors from the bulk insert.
Does the table in SQL Management studio have the correct data?
If you have the correct data trying just reading as a data table to see what is brought back as that will be object values rather than a specific type.