473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to truncate automatically?

Hi,

When the length of a textbox in a form exceeds the length of the
corresponding field, i get an error message ("string or binary data will be
truncated .... ") and the aplication stops.

I know i can check the lenght in code-behind, but is there no way to let
asp.net truncate inputted data automatically and not let it stop the
application and show that error message?

Thanks
Chris
Jul 12 '07 #1
6 2113
Hi Chris,

You should check a length of input (form) string and set the length constrain
in a sql parameter of sql command, like SqlParameter("@value", SqlDbType.VarChar,
<set_cetrain_size_there>).

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
Jul 12 '07 #2
"Chris" <gd***@er.dfwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
When the length of a textbox in a form exceeds the length of the
corresponding field, i get an error message ("string or binary data will
be truncated .... ") and the aplication stops.

I know i can check the lenght in code-behind, but is there no way to let
asp.net truncate inputted data automatically and not let it stop the
application and show that error message?
A couple of solutions:

Firstly, the <asp:TextBoxcontrol has a MaxLength property. If e.g. your
database field is varchar(50), setting the MaxLength also to 50 will prevent
your users from typing more text than will fit in the database.

Secondly, you can return the first n characters from a TextBox control like:
TextBox.Text..Substring(0, 50);

The first option is preferable, IMO. If you allow users to enter more data
than the database can accept, next time they visit the record they may
believe that an error has occurred...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 12 '07 #3
On Jul 12, 3:10 pm, "Chris" <g...@er.dfwrote:
Hi,

When the length of a textbox in a form exceeds the length of the
corresponding field, i get an error message ("string or binary data will be
truncated .... ") and the aplication stops.

I know i can check the lenght in code-behind, but is there no way to let
asp.net truncate inputted data automatically and not let it stop the
application and show that error message?

Thanks
Chris
Hi...

I am not quite sure that this will help but still, please do checkout
this forum post...
http://forums.asp.net/p/436606/437849.aspx

Thanks
Md. Masudur Rahman (Munna)
kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com

Jul 12 '07 #4
Chris wrote:
Hi,

When the length of a textbox in a form exceeds the length of the
corresponding field, i get an error message ("string or binary data
will be truncated .... ") and the aplication stops.

I know i can check the lenght in code-behind, but is there no way to
let asp.net truncate inputted data automatically and not let it stop
the application and show that error message?
The best way in my opinion is to set the maxlength property on the textbox.

--

Riki
Jul 12 '07 #5
Thanks to all,

one remark: Maxlength doesn't work when mode is Multiline ...
"Masudur" <mu*****@gmail.comschreef in bericht
news:11**********************@q75g2000hsh.googlegr oups.com...
On Jul 12, 3:10 pm, "Chris" <g...@er.dfwrote:
>Hi,

When the length of a textbox in a form exceeds the length of the
corresponding field, i get an error message ("string or binary data will
be
truncated .... ") and the aplication stops.

I know i can check the lenght in code-behind, but is there no way to let
asp.net truncate inputted data automatically and not let it stop the
application and show that error message?

Thanks
Chris

Hi...

I am not quite sure that this will help but still, please do checkout
this forum post...
http://forums.asp.net/p/436606/437849.aspx

Thanks
Md. Masudur Rahman (Munna)
kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com

Jul 12 '07 #6
Chris wrote:
Thanks to all,

one remark: Maxlength doesn't work when mode is Multiline ...
In that case, another option, not yet mentioned, is to use a validator
(Regular Expression Validator) on the textbox.

--

Riki
Jul 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: martin | last post by:
Hi, We have a heavily used production server and a table which logs every hit on a web site. This table has grown large over time and we want to clear it down as efficiently as possible. We would...
3
by: LineVoltageHalogen | last post by:
Greeting All, I have a stored proc that dynamically truncates all the tables in my databases. I use a cursor and some dynamic sql for this: ...... create cursor Loop through sysobjects and...
1
by: New MSSQL DBA | last post by:
I have recently been assigned to take over several MSSQL environments and found some of the existing practice confusing. As most of my previous experiences are on Oracle and Unix platform so would...
2
by: rdraider | last post by:
Hi, I am trying to create a script that deletes transaction tables and leaves master data like customer, vendors, inventory items, etc. How can I use TRUNCATE TABLE with an Exists? My problem is...
9
by: Sumanth | last post by:
Are there any implementations of truncate in db2. Is it going to be implemented in the future? Is there an alternate way of doing a truncate of a table that has a high record count without using...
14
by: Sala | last post by:
Hi I want to truncate all data in database ... pls help me how i ll truncate?
10
by: Troels Arvin | last post by:
Hello, Until this date, I believed that DB2 has no TRUNCATE TABLE command. But then I came across...
5
by: Timothy Madden | last post by:
Hello I see there is now why to truncate a file (in C or C++) and that I have to use platform-specific functions for truncating files. Anyone knows why ? I mean C/C++ evolved over many years...
8
by: ananthaisin | last post by:
How to reduce the table size for any table while using truncate or delete statements. In oracle 8i it was truncating the storage space but in 10g it is not .... I have given truncate statement in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.