How can i get the whole string with SqlDataReader?

  • Thread starter Thread starter smeagol
  • Start date Start date
S

smeagol

I have a varchar 255 field in the Sql.
When i get the data with (string)myReader["buffer"];
it's trimed

ie(
SQL : "qwerty " (Lenght 255)
c# : (string)myReader["buffer"].Lenght; (=5)

It's possible to get
(string)myReader["buffer"].Lenght; (=255)

Of course a trick is to use PADL with SPACE

But anyway to do it wihout PADL?

Thanks,
 
smeagol,

If you need the padding, then why not define the field as a char field?
This way, you always get the padding.

You could always call the sp_columns stored procedure (once), and get
the length of the field from that (you can store it as well, since your
schema should not change during the course of execution) and pad
appropriately.

Hope this helps.
 
Back
Top