Have below code
AcctNbr give me result of 30.
That is the database column length, Column stores 10 why is giving me
30 ?
while(objRead.R ead())
{
AcctNbr = (string)objRead[0].ToString().Len gth;
Console.WriteLi ne("Length is {0}",AcctNbr.Le ngth);
} 7 2538
Matt wrote: Have below code AcctNbr give me result of 30. That is the database column length, Column stores 10 why is giving me 30 ?
while(objRead.R ead()) { AcctNbr = (string)objRead[0].ToString().Len gth; Console.WriteLi ne("Length is {0}",AcctNbr.Le ngth); }
I don't know that I have an answer to your question but it seems what
you are doing here isn't quite right.
This line returns the length of objRead after converting it to a string.
This value is an integer. You then convert that integer into a
string. So AcctNbr now hold something like 10 in string form.
AcctNbr = (string)objRead[0].ToString().Len gth;
Here you take your string value of 10 and get the length of that string
value. so the answer to AcctNbr.Length would be 2. I don't think this
is what you ment to do.
Console.WriteLi ne("Length is {0}",AcctNbr.Le ngth);
Chris
I just like to get the string lenght of the stored value ?
so i can compare that length..
Matt wrote: I just like to get the string lenght of the stored value ? so i can compare that length..
What is the object type in the datareader? String?
int intLen
intLen = objRead[0].ToString().Len gth
or
intLen = objRead.GetStri ng(0).Length
Console.WriteLi ne("Length is {0}",intLen.ToS tring())
That should give you the length.
Chris
Chris am still getting 30. I have tried those before thats where i
dont get it.
data column is char and stored 10 char value '5559878789'
int intlen;
while(objRead.R ead())
{
intLen = objRead.GetStri ng(0).Length;
Console.WriteLi ne("Length is {0}",intLen.ToS tring()) ;
}
Length is 30
If anyone interested, I just used trim to get rid of the space for
string.
It sucks. but what can u do Thats MS for you.
intLen = objRead.GetStri ng(0).Length;
Console.WriteLi ne("Length is {0}",intLen.ToS tring());
Console.WriteLi ne(objRead[0].GetType());
string x = objRead[0].ToString();
Console.WriteLi ne("String x is {0}",x);
Console.WriteLi ne(x.Length);
string y = x.Trim();
Console.WriteLi ne(y.Length);
Matt wrote: If anyone interested, I just used trim to get rid of the space for string. It sucks. but what can u do Thats MS for you. intLen = objRead.GetStri ng(0).Length; Console.WriteLi ne("Length is {0}",intLen.ToS tring()); Console.WriteLi ne(objRead[0].GetType()); string x = objRead[0].ToString(); Console.WriteLi ne("String x is {0}",x); Console.WriteLi ne(x.Length); string y = x.Trim(); Console.WriteLi ne(y.Length);
You have the variable in the database declared as Char(30) I bet.
Change it to varchar(30) and it will work the way you were expecting.
Chris
Not Allowed to change database
Thanks though This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter Scott |
last post by:
I created a table that has a column in that needs to contain a full
Unix file path. Since 2048 was too long for a VARCHAR, I made it
TEXT. I since populated the table. Now I want to make the path
column a primary key, and I can't figure out how. (I googled the
web and groups without luck, looked over the reference manual also,
especially reading the entry on BLOBs.)
I was able to make a fulltext index with:
create fulltext index...
|
by: Philip Sherman |
last post by:
I'm trying to copy production statistics to a test database and can't
set the column statistics for a VARGRAPHIC column to match what RUNSTATS
generated on production.
The reason code and some testing I did indicates that the length of the
low2key value is too long. It almost looks like the potential length of
data to be stored is being calculated on the length of the hex string;
without consideration that two bytes of the string...
|
by: nimdez |
last post by:
Hi,
I am working on an existing code base in which a lot of data displayed
to the user is formatted in tables. Most tables are printed row-by-row
using printf() with "%s" print conversion specification for
each column (e.g. printf(%10s %25s %15s\n", pszCol1, pszCol2,
pszCol3)). My problem is that when a string is longer the column's
width, it overflows the column and takes the table out of alignment.
What I want it to do is word-wrap...
|
by: PeterZ |
last post by:
Hi,
In a running C# app with a datagrid control I select all rows in the
dataGrid using CTRL-A, I then paste into some other app like notepad or Word
but the column headings get left off.
Is there any way of including column headings when copying/pasting from a
running datagrid to notepad? At this stage it looks like I have to write my
own code but would rather not if someone knows how to do it.
|
by: venky |
last post by:
HI guys,
In one of my columns in the grid, i want to set the width of the grid
to the widest entry in the column when i click on the column seperator.
How can i calcualte the column width if i know the lenght of the
longest string?
| |
by: Aaron Smith |
last post by:
Is there a way to put a limit on the text size of a datagrid column?
Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
|
by: CindyH |
last post by:
Hi
Does anyone know how to create a multi column combo box from the same table?
Thanks,
Cindy
|
by: Javier |
last post by:
Hi Everyone,
I have a dynamic checkbox in a datagrid that uses the ITemplate interface
and has the checkchanged event wired up. When the checkbox is checked, the
event
event handler that handles the event gets called, however when it is
unchecked, it does not fire. Is this by design, or is something else that
is going on? Thanks!!.
This message was originally posted by marian@discussions.microsoft.com, but
|
by: Mel |
last post by:
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:
gvParts.Rows(e.RowIndex).Cells(8).Text
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |