开发者

C# Need code to stop exporting header row

Hey guys, I have this quick bit of code that I can't figure out how to stop exporting the header row.

the results are

PrimaryRowGuid|Text  
| blah blah blahg blah  
blah blah blahg blahblah blah blahg blah  
blah blah blahg blah

I need the results to be:

blah blah blahg blah  
blah blah blahg blahblah blah blahg blah  
blah blah blahg blah

Any help is appricated!

using (StreamWriter writer = new StreamWriter(strm))
{
    SqlCommand cmd = new SqlCommand(sql, con);
    SqlDataReader reader = cmd.ExecuteReader();
    for (int i = 0; i < reader.FieldCount; i++)
        writer.Write((i == 0 ? "" : "|") + reader.GetName(i));
    writer.Write("\n");
    while (reader.Read())
    {
        for (int i = 1; i < reader.FieldCount; i++)
            writer.Write((i开发者_如何学JAVA == 0 ? "" : "|") + reader[i].ToString().Replace(@"<swme> ", string.Empty).Replace(@" </swme>|", "|").Replace(@" </swme>", ";").Replace('\r', ' ').TrimEnd((char)';'));
        writer.WriteLine();
    }
    reader.Close();


The header row is exported by the following lines of code:

    for (int i = 0; i < reader.FieldCount; i++)
        writer.Write((i == 0 ? "" : "|") + reader.GetName(i));
    writer.Write("\n");

I assume you can figure out from here how to get rid of it.


Just take out the reader.Read block of code and you will be fine


for (int i = 0; i < reader.FieldCount; i++)
    writer.Write((i == 0 ? "" : "|") + reader.GetName(i));
writer.Write("\n");

Delete that block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜