473,394 Members | 1,718 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,394 software developers and data experts.

Find maimum length of a varchar database column

121 100+
I have a database which has a column of type VARCHAR(30). I want to insert a string into this column using ADO .net. I first want to make sure that the string will be able to fit into the column in the database. If it can fit, I will insert the whole string. If not, I will truncate the string so that it will fit.

If I read the desired table into an SqlDataAdapter and then fill a dataTable, there is a property in dataTable.Columns.Item("Column") called MaxLength, but it always returns -1.

I want to use some method that will return 30. Any ideas?
May 9 '08 #1
3 1876
Plater
7,872 Expert 4TB
Inserting a string that is too long will automatically truncate it. Unless you want special rules for truncating?
May 9 '08 #2
Sick0Fant
121 100+
Inserting a string that is too long will automatically truncate it. Unless you want special rules for truncating?
Then I guess I'd only need to know if it *was* truncated. Is there anyway of checking that without querying the db again to see if what was inserted is the same as what I tried to insert?

Also, why does MaxLength return -1?
May 9 '08 #3
Plater
7,872 Expert 4TB
http://forums.asp.net/p/306971/306971.aspx

According to them, maxlength is -1 on integer fields, but should work fine for text fields(varchar() )
May 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kelly Prendergast | last post by:
Hi all, I need to change a varchar from 35 to 50. In the SQL Server books on line it says that SQL Server actually creates a new table when you change the length. I ran a test in a test database...
5
by: Edward Mitchell | last post by:
I have a database with text string fields defined by varchar(nnn). When I request from the user the text from a textbox, I'd like to set the maximum number of characters in the textbox to the...
1
by: Poul Møller Hansen | last post by:
I have created a db2 8.1 database with codeset UTF-8. I thought the database was able to handle field legths as characters and not as byte data then. But I'm getting an error when inserting a 20...
11
by: mailar | last post by:
Hi, I am using DB2 version 8.2 on Windows XP platform. I have a table 'EMP' with one field named 'NAME' of type CHAR , size 80. Also , I have a record with NAME='john' Now, when I try to...
3
by: Bob Stearns | last post by:
I changed a varchar(255) to varchar(3000) an started receiving: Warning: odbc_exec(): SQL error: SQL1585N A system temporary table space with sufficient page size does not exist. SQLSTATE=54048...
1
by: Dan Manes | last post by:
Wondering what other people do about this issue... You're writing a web app in asp.net that requires user input. Data will be stored in SQL Server Express database. You want to make sure data...
2
by: Frank Swarbrick | last post by:
I'm just learning about embedded SQL, so be gentle... My basic question is, if I use a fixed length host variable for a column defined as VARCHAR, will trailing spaces be removed (or not) upon...
2
by: John | last post by:
Hi Everyone, I have a question about dynamically changing the length of a varchar(n) field, in case the value I'm trying to insert is too big and will give a "truncated" error, but before the...
6
by: mike | last post by:
so I keep optimizing my fields down to the minimum character length necessary i.e., varchar(15), then I find out a month later its gotta get bigger, then a few months later, bigger again, etc. ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.