DataReader to .CSV with column names

前端 未结 5 976
清酒与你
清酒与你 2020-12-15 10:49

I\'m generating a csv file from an SqlDataReader, however it is not writing the column names, how can I make it write them? The code I\'m using is as follows:



        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 11:13

    You can use the SqlDataReader.GetName method to get the name of a column, like this:

    for(int i = 0; i < reader.FieldCount; i++)
    {
        string columnName = reader.GetName(i);
    }
    

提交回复
热议问题