Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Turn off SQL truncate?

Author  Topic 

stupidnoob
Starting Member

1 Post

Posted - 2007-07-10 : 16:13:25
I have a nvarchar(256) column and when I am using C# code to add data to it. When I enter data over 256 characters long, it automatically truncates. When I try to do this is the Query Editor, it will not allow me to and terminates with the error "Binary data or string would be truncated"

Is there a way to turn this automatic truncating off?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-07-10 : 16:40:54
I don't understand what you want ... what do you want to change? The way your C# code works? What should happen when the data is too long if it doesn't truncate, return an error?

How about some example code showing what you are talking about? It is hard to guess without seeing how you are coding things.


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-07-10 : 16:44:14
Make the column longer.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-10 : 17:19:35
quote:
Originally posted by rmiao

Make the column longer.



I don't see that this is a solution for this problem. Even if you make it bigger, this issue will still happen if the user submits one extra character beyond what the column can hold.

If you don't want it to truncate, then you need to modify your application to check the length of the data versus the length of the field and either return an error or do something else.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-07-11 : 07:04:30
quote:

If you don't want it to truncate, then you need to modify your application to check the length of the data versus the length of the field and either return an error or do something else.

Tara Kizer
http://weblogs.sqlteam.com/tarad/



Sorry, this is the correct way to do things. Could you suggest something more obscure or perhaps involving cursors?


[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -