简体   繁体   中英

Determine data size of row using SqlDataReader

I am trying to determine the amount of data returned to a .NET application from SQL Server for an arbitrary SQL command. The column structure is not known at compile-time. I'm not interested in the data itself, just the length.

long size = 0;
using (SqlDataReader reader = cmd.ExecuteReader())
{
    while (reader.Read())
    {
        //size += size of current reader row ?
    }
}

Is there any way to do this?

If with size of the row you mean the amount of columns, you could use reader. FieldCount or reader. VisibleFieldCount

long size = 0;
using (SqlDataReader reader = cmd.ExecuteReader())
{
    while (reader.Read())
    {
        size += reader.FieldCount;
    }
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM