How can i get the whole string with SqlDataReader?

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,
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top