Hi guys, this is my first project, I am a beginner programmer so my C# skills are few for now.
What I have to do is create a console application that extracts a single table, from an access database, using a SQL query in app.config, so that it is possible to change the SQL without changing the code in the application.
The extracted information has to be in a text file format. The hard part is that I have and excel file with the mapping of the that table and i only need to extract that information, and add some other.
For example I will need to create a new column that is not originally in the datatable and give it a default value. And that information is on the excel file.
Basically I already have the connections done and I extracted a table that I need from the access database, for a temporary datatable, I already have a datatable from the excel file with only the columns I will need to use in a temporary datatable.
I need to create a foreach loop to check if the A column in excel is in use, if yes then I need to check another column that contains the name of the that column in the access datatable, if there is a value I need to to extract that column to the text file, if there is no value I need to check other column that contains a default value and I need to add that value to a column that doesn't exist in the database. If there are no values in both those columns than I need to just add a blank space with the width value in the text file.
All this columns extracted to the text file need to have the width-string.width has a blank space between them and there is no need to extract the column names.
This what i have so far. It may be really wrong, so any help would be appreciated
static void createfile(DataTable accessTable, DataTable excelTable)
{
string strFileData = "";
foreach(DataRow accessRow in accessTable.Rows)
{
foreach (DataRow excelrow in excelTable.Rows)
{
string fieldname = "";
fieldname = excelrow["FieldName"]
strFileData.insert accessRow[fieldname];
string test = accessRow[fieldname.ToString()];
if(position == 0)
strFileData = strFileData.Insert(0,ColumnName.ToString().PadLeft(width, '0'));
}