0

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!
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
B. P.
  • 1
  • 2
  • 1
    What is the length of the field in the database table definition? – jdweng Aug 11 '17 at 17:17
  • 2
    Why are you saying "bytes"? `varchar/nvarchar` columns and strings are measured in Characters, not Bytes. And a Character is not necessarily a single byte (though assuming UTF-16, it's 2 or 4 bytes per character). – Dai Aug 11 '17 at 17:18
  • 1
    Also, it's `SqlDataReader`, not `SqlReader` - unless you're using some other library? – Dai Aug 11 '17 at 17:18
  • I said "bytes" because I write the results to a file, and the file has a size, which is measured in bytes. I have changed it. – B. P. Aug 11 '17 at 21:29

1 Answers1

0

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