Jump to content

Help... It's linq to Sql

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Tonaldex

Tonaldex

    Newbie

  • Members
  • Pip
  • 8 posts
Gudevening fellow programmer, am currently working on linq to sql. Am trying to insert entities into database using d Context.insertallonsubmit() method but i got d error "STRING OR BINARY DATA WOULD BE TRUNCATED" Meanwhile, i have check every data lenght on database to avoid Lenght overflow, i still get the same exception. But when i try inserting the same data manually from d database, it insert succesfully. Pls wat can i do. Any suggestion would be highly appreciated.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Are you trying trying to insert unicode data into a non-unicode field?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
the linq to sql classes would convert that on the fly you would think
since in .NET a string is just a string, and the entity classes generated would expose as string.

did you change the field length in the database since you generated the linq to sql mapping?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
The problem is this: 8 Unicode characters can occupy 24 characters in a non-Unicode field. Suddenly, what looked like it was small enough to fit, isn't.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
yeah, no I get that
I just mean that once you're in a string type in .NET, the unicode aspect shouldn't hold much weight.

for example, to write a string to a non unicode type, one might write

Encoding.UTF8.GetBytes("some value");



or to keep it in a unicode encoding, one might say

Encoding.Unicode.GetBytes("some value");



When one generates the entity classes with linq to SQL, it automatically generates the classes as well as any serialization that needs to take place between the tables, so you shouldnt need to worry about that. I believe that all strings in .NET are internally handled as unicode, so if you have a non unicode field in SQL Server, something like this


command.Parameters.AddWithValue("@name", "sam");


would not turn out like this:
" s a m"

but I'm only speculating...




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users