473,398 Members | 2,404 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,398 software developers and data experts.

Sorting problem: Conversion from String(varchar) to Int32

Hi,

I have a column in my WinGrid, that's being populated with numeric data, but
it's of String datatype(business rule requires to have these numbers as
varchars in DB). On top of that, I need to be able to sort on that
particular column. But because column contains character data(even though it
looks like digits), the sorting is all out of whack, e.g, 1, 11, 12,
13.....2, 21, 22, so on, you got the picture.I'm using the typed dataset as
a datasource for the grid, so I changed the column's datatype in the
datasource to Int32. Additionaly, I cast the column when I retrieve it in
Proc.(SELECT CONVERT(INT,ColumnName....). But it doesn't work, I mean it's
getting sorted in exactly the same way it did before.
I also tried to explicitly cast it before setting the grid's datasource:
For iRow = 0 To dsTyped.Tables("TableName").Rows.Count - 1

If Not dsTyped.Tables("TableName").Rows(iRow)(ColumnName) Is
GetType(System.Int32) ThendsTyped.Tables("TableName").Rows(iRow)(ColumnN ame)
= CType(dsTyped.Tables("TableName").Rows(iRow)(Colum nName), System.Int32)

End If

Next

Please advise or tell me what I'm doing wrong.

Thanks, Alex Ayzin
Nov 20 '05 #1
2 1138
If the Typed dataset is set to string for that column, then it will override
whatever you send into it.

So, even though your converting it in two different ways, the final result
in the typed dataset is that it is defined as a string...

So...

the value is converted to string which is why your sort doesn't work.

Fix...

change your typed dataset.

-CJ
"Alex Ayzin" <Al********@verizon.net> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a column in my WinGrid, that's being populated with numeric data, but it's of String datatype(business rule requires to have these numbers as
varchars in DB). On top of that, I need to be able to sort on that
particular column. But because column contains character data(even though it looks like digits), the sorting is all out of whack, e.g, 1, 11, 12,
13.....2, 21, 22, so on, you got the picture.I'm using the typed dataset as a datasource for the grid, so I changed the column's datatype in the
datasource to Int32. Additionaly, I cast the column when I retrieve it in
Proc.(SELECT CONVERT(INT,ColumnName....). But it doesn't work, I mean it's
getting sorted in exactly the same way it did before.
I also tried to explicitly cast it before setting the grid's datasource:
For iRow = 0 To dsTyped.Tables("TableName").Rows.Count - 1

If Not dsTyped.Tables("TableName").Rows(iRow)(ColumnName) Is
GetType(System.Int32) ThendsTyped.Tables("TableName").Rows(iRow)(ColumnN ame) = CType(dsTyped.Tables("TableName").Rows(iRow)(Colum nName), System.Int32)

End If

Next

Please advise or tell me what I'm doing wrong.

Thanks, Alex Ayzin

Nov 20 '05 #2
OK, thanks a lot, guys for all of your replies. Here's what I've done and
it's working great:

1. Cast numeric text inside the procedure;
2. In the typed dataset, change the datatype of the column in question from
String to Int(it's gotta be Int, not Integer, otherwise exception is
thrown, type mismatch).
3. Setup SortIndicator(I'm using Infragistics WinGrid).

That's it. Works great.
Thanks again,
--Alex Ayzin
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:vt************@corp.supernews.com...
If the Typed dataset is set to string for that column, then it will override whatever you send into it.

So, even though your converting it in two different ways, the final result
in the typed dataset is that it is defined as a string...

So...

the value is converted to string which is why your sort doesn't work.

Fix...

change your typed dataset.

-CJ
"Alex Ayzin" <Al********@verizon.net> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a column in my WinGrid, that's being populated with numeric data, but
it's of String datatype(business rule requires to have these numbers as
varchars in DB). On top of that, I need to be able to sort on that
particular column. But because column contains character data(even though it
looks like digits), the sorting is all out of whack, e.g, 1, 11, 12,
13.....2, 21, 22, so on, you got the picture.I'm using the typed dataset

as
a datasource for the grid, so I changed the column's datatype in the
datasource to Int32. Additionaly, I cast the column when I retrieve it

in Proc.(SELECT CONVERT(INT,ColumnName....). But it doesn't work, I mean it's getting sorted in exactly the same way it did before.
I also tried to explicitly cast it before setting the grid's datasource:
For iRow = 0 To dsTyped.Tables("TableName").Rows.Count - 1

If Not dsTyped.Tables("TableName").Rows(iRow)(ColumnName) Is
GetType(System.Int32)

ThendsTyped.Tables("TableName").Rows(iRow)(ColumnN ame)
= CType(dsTyped.Tables("TableName").Rows(iRow)(Colum nName), System.Int32)
End If

Next

Please advise or tell me what I'm doing wrong.

Thanks, Alex Ayzin


Nov 20 '05 #3

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

Similar topics

3
by: Alex Ayzin | last post by:
Hi, I have a column in my WinGrid, that's being populated with numeric data, but it's of String datatype(business rule requires to have these numbers as varchars in DB). On top of that, I need...
3
by: Bern | last post by:
is there some way to convert a hex string to an int and vice versa
1
by: Marty | last post by:
Hi, I took this socket listener from the VC++.NET help file. I inserted it in my project. What library do I have to include to have those identifier working: string, int32, Byte, server,
2
by: Robert Fitzpatrick | last post by:
I have varchar column with both numbers and letters, like 1 thru 10 and 5A thru 5G, they are unit numbers for apartments. If I have 1 thru 100, since it is a varchar field, it sorts like 1,10,11......
4
by: mark.olszowka | last post by:
I am writing a generic property table as part of my application property_name property_type property_value All information is stored in the database as strings. In my application that...
15
by: angellian | last post by:
Sorry to raise a stupid question but I tried many methods which did work. how can I conserve the initial zero when I try to convert STR(06) into string in SQL statment? It always gives me 6...
4
by: Brian Parker | last post by:
I've been banging my head on this for hours and it's something that should be very very easy. I have a Stored Procedure in a MS-SQL 2000 server that returns a Varchar(40) and I want to grab that...
0
by: Stefan Mähr | last post by:
Hello Community, I got a problem using a Delphi COM DLL (written in Delphi7) within my VB.NET 2005 Project, I can create an Instance of the variable without Problems, but when I call a Function...
0
by: manoj339 | last post by:
I have varchar variable declared .When I print this var it shows me correct value before a C function. Inside a c function this variable value is getting truncated . The c function does not pass...
1
by: mshemalatha | last post by:
Hi, String(Varchar) ID generation in Sql Server 2005 & NET for example ABC01,ABC02... and another example IN01,DN02,AM03,PK04,CN05,
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: 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
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
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...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.