.NET and SQL types

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am doing some DB work and have a question about type conversion.

I have a column in my database that is a varchar(255)

If i only use some of the space, e.g store "car" in this field, when i fetch
it from the database and assing it to a .NET string how much memory will this
string occupy.

Will it be 255 bytes or the actual size of the data stored in the field?

Thanks
Macca
 
Neither;

the varchar SQL type is variable length, so it shouldn't contain unnecessary
whitespace to confuse things; this means the string you get back into .Net
will be 3 characters long... however, characters are not bytes... unless I
am mistaken, .Net uses UTF-16, so 2 bytes per character, plus the overheads
for the objects... but in essense: yes, the size will be proportional to the
length of the string (plus a small fixed overhead)

Marc
 

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

Back
Top