简体   繁体   中英

Using SqlReader, when using reader.GetString(1) -OR- reader[“Details”], it only retrieves 4000 bytes of the string. How do I get the rest?

I have instantiated an SqlDataReader, and when using reader.GetString(1) -OR- reader["Details"], it only retrieves the first 4000 characters of the string. How do I get the rest?

SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
    while (reader.Read())
    {
        string foo = reader["Name"];
        string bar = reader.GetString(1);    //reader["Details"];
        // bar ONLY has the first 4000 bytes - not the entire field!
    }
}

Is the Details column in your database typed as text or ntext? If so, you need to use a method similar to that for blob data:

How to read and write a file to and from a BLOB column by using chunking in ADO.NET and Visual C# .NET

It's worth noting that TEXT and NTEXT are being deprecated. nvarchar and varchar are likely the types you are looking for.

see: SQL Server Text type vs. varchar data type

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