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.
4 replies to this topic
#1
Posted 07 June 2011 - 10:27 AM
|
|
|
#2
Posted 07 June 2011 - 05:36 PM
Are you trying trying to insert unicode data into a non-unicode field?
#3
Posted 07 June 2011 - 06:27 PM
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?
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
Posted 08 June 2011 - 04:14 PM
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.
#5
Posted 08 June 2011 - 07:07 PM
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
or to keep it in a unicode encoding, one might say
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
" s a m"
but I'm only speculating...
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


Sign In
Create Account

Back to top









