I am doing this:
using (TextFieldParser parser = new TextFieldParser(ConfigurationManager.AppSettings[Constants.FILE], Constants.ENCODING))
{
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(",");
parser.HasFieldsEnclosedInQuotes = true;
string[] colFields = parser.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
if (column == "Column001")
{
}
}
}
What I want to do is when column name equals variable I want to add it to datatable column and get it's index ID(I want to know what colFields[?] have the name of variable)
If you want to know the index of the column, you should use a for
loop instead:
for (int i = 0; i < colFields.Length; ++i)
{
string column = colFields[i];
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
if (column == "Column001")
{
}
}
As you can see, you now have the index in i
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.