Another option you have is to read the data into a DataTable
. This represents the data basically the same as a list of a custom type without having to create that type.
Once the data is read, it can be searched for null values and the return set accordingly, or if it might be desired it is relatively simple to return a set of rows that contain the incomplete data.
Simple function for this could look like this:
public DataTable GetIPNFPTechFromCSV(string fileName)
{
const string BOM = "";
string directory = System.IO.Path.GetDirectoryName(fileName);
if( directory == "")
{
directory = @".\";
}
string file = System.IO.Path.GetFileName(fileName);
OdbcConnection conn = new OdbcConnection($@"Driver={{Microsoft Text Driver (*.txt; *.csv)}};Dbq={directory};FMT=Delimited','");
OdbcCommand comusing (OdbcDataAdapter da = new OdbcCommandOdbcDataAdapter($@"Select FPTech, PartNumber* from [{file}]", conn);)
DataTable dt = new DataTable();
using (OdbcDataAdapter da = new OdbcDataAdapter(com))
{
da.Fill(dt);
}
if(dt.Columns[0].ColumnName.StartsWith(BOM))
{
dt.Columns[0].ColumnName = dt.Columns[0].ColumnName.Trim(BOM.ToArray());
}
bool goodData = dt.Select().All(x => !x.ItemArray.Contains(DBNull.Value));
if(goodData)
{
return dt;
}
else
{
return null;
}
}
Another option you have is to read the data into a DataTable
. This represents the data basically the same as a list of a custom type without having to create that type.
Once the data is read, it can be searched for null values and the return set accordingly, or if it might be desired it is relatively simple to return a set of rows that contain the incomplete data.
Simple function for this could look like this:
public DataTable GetIPNFPTechFromCSV(string fileName)
{
const string BOM = "";
string directory = System.IO.Path.GetDirectoryName(fileName);
if( directory == "")
{
directory = @".\";
}
string file = System.IO.Path.GetFileName(fileName);
OdbcConnection conn = new OdbcConnection($@"Driver={{Microsoft Text Driver (*.txt; *.csv)}};Dbq={directory};FMT=Delimited','");
OdbcCommand com = new OdbcCommand($@"Select FPTech, PartNumber from [{file}]", conn);
DataTable dt = new DataTable();
using (OdbcDataAdapter da = new OdbcDataAdapter(com))
{
da.Fill(dt);
}
if(dt.Columns[0].ColumnName.StartsWith(BOM))
{
dt.Columns[0].ColumnName = dt.Columns[0].ColumnName.Trim(BOM.ToArray());
}
bool goodData = dt.Select().All(x => !x.ItemArray.Contains(DBNull.Value));
if(goodData)
{
return dt;
}
else
{
return null;
}
}
Another option you have is to read the data into a DataTable
. This represents the data basically the same as a list of a custom type without having to create that type.
Once the data is read, it can be searched for null values and the return set accordingly, or if it might be desired it is relatively simple to return a set of rows that contain the incomplete data.
Simple function for this could look like this:
public DataTable GetIPNFPTechFromCSV(string fileName)
{
const string BOM = "";
string directory = System.IO.Path.GetDirectoryName(fileName);
if( directory == "")
{
directory = @".\";
}
string file = System.IO.Path.GetFileName(fileName);
OdbcConnection conn = new OdbcConnection($@"Driver={{Microsoft Text Driver (*.txt; *.csv)}};Dbq={directory};FMT=Delimited','");
using (OdbcDataAdapter da = new OdbcDataAdapter($@"Select * from [{file}]", conn))
DataTable dt = new DataTable();
using (OdbcDataAdapter da = new OdbcDataAdapter(com))
{
da.Fill(dt);
}
if(dt.Columns[0].ColumnName.StartsWith(BOM))
{
dt.Columns[0].ColumnName = dt.Columns[0].ColumnName.Trim(BOM.ToArray());
}
bool goodData = dt.Select().All(x => !x.ItemArray.Contains(DBNull.Value));
if(goodData)
{
return dt;
}
else
{
return null;
}
}
Another option you have is to read the data into a DataTable
. This represents the data basically the same as a list of a custom type without having to create that type.
Once the data is read, it can be searched for null values and the return set accordingly, or if it might be desired it is relatively simple to return a set of rows that contain the incomplete data.
Simple function for this could look like this:
public DataTable GetIPNFPTechFromCSV(string fileName)
{
const string BOM = "";
string directory = System.IO.Path.GetDirectoryName(fileName);
if( directory == "")
{
directory = @".\";
}
string file = System.IO.Path.GetFileName(fileName);
OdbcConnection conn = new OdbcConnection($@"Driver={{Microsoft Text Driver (*.txt; *.csv)}};Dbq={directory};FMT=Delimited','");
OdbcCommand com = new OdbcCommand($@"Select FPTech, PartNumber from [{file}]", conn);
DataTable dt = new DataTable();
using (OdbcDataAdapter da = new OdbcDataAdapter(com))
{
da.Fill(dt);
}
if(dt.Columns[0].ColumnName.StartsWith(BOM))
{
dt.Columns[0].ColumnName = dt.Columns[0].ColumnName.Trim(BOM.ToArray());
}
bool goodData = dt.Select().All(x => !x.ItemArray.Contains(DBNull.Value));
if(goodData)
{
return dt;
}
else
{
return null;
}
}