473,606 Members | 3,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(busine ss 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,Col umnName....). 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").Ro ws.Count - 1

If Not dsTyped.Tables( "TableName").Ro ws(iRow)(Column Name) Is
GetType(System. Int32) ThendsTyped.Tab les("TableName" ).Rows(iRow)(Co lumnName)
= CType(dsTyped.T ables("TableNam e").Rows(iRow)( ColumnName), System.Int32)

End If

Next

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

Thanks, Alex Ayzin
Nov 22 '05 #1
3 2251
Dear Alex,

I have tried the following select query....
Select discounttype, stor_id, lowqty, highqty, discount,
Convert(int, PTColumn) From Discounts

This is a table of the Pubs database with PTColumn as a
new varchar column added.

I have tried opening the dataset (through SQLConnection,
SQLAdapter....) and then bound it to the datagrid control.
Following is the code snippet...

System.Data.Dat aSet ds = new System.Data.Dat aSet();

System.Data.Sql Client.SqlConne ction sqlConn = new
System.Data.Sql Client.SqlConne ction("Data
Source=MACNAME; Initial Catalog=Pubs;Us er
Id=sa;Password= ;");

sqlConn.Open();

System.Data.Sql Client.SqlDataA dapter sqlAdp = new
System.Data.Sql Client.SqlDataA dapter("Select
discounttype, stor_id, lowqty, highqty, discount, Convert
(int, PTColumn) From Discounts", sqlConn);

sqlAdp.Fill(ds) ;

this.dataGrid1. DataSource = ds;

I have tried this out and it works fine. Also in case if
you are using typed dataset, ensure that in the InitClass
() function the column constructor is called with the
datatype set to typeof(int).

Hope this may resolve your problem.

Regards,
Puneet Taneja
-----Original Message-----
Hi,

I have a column in my WinGrid, that's being populated with numeric data, butit's of String datatype(busine ss rule requires to have these numbers asvarchars in DB). On top of that, I need to be able to sort on thatparticular column. But because column contains character data(even though itlooks 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 asa datasource for the grid, so I changed the column's datatype in thedatasource to Int32. Additionaly, I cast the column when I retrieve it inProc.(SELECT CONVERT(INT,Col umnName....). But it doesn't work, I mean it'sgetting 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").Ro ws.Count - 1
If Not dsTyped.Tables( "TableName").Ro ws(iRow) (ColumnName) IsGetType(System .Int32) ThendsTyped.Tab les ("TableName").R ows(iRow)(Colum nName)= CType(dsTyped.T ables("TableNam e").Rows(iRo w) (ColumnName), System.Int32)
End If

Next

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

Thanks, Alex Ayzin
.

Nov 22 '05 #2
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********@ver izon.net> wrote in message
news:eX******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a column in my WinGrid, that's being populated with numeric data, but it's of String datatype(busine ss 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,Col umnName....). 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").Ro ws.Count - 1

If Not dsTyped.Tables( "TableName").Ro ws(iRow)(Column Name) Is
GetType(System. Int32) ThendsTyped.Tab les("TableName" ).Rows(iRow)(Co lumnName) = CType(dsTyped.T ables("TableNam e").Rows(iRow)( ColumnName), System.Int32)

End If

Next

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

Thanks, Alex Ayzin

Nov 22 '05 #3
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****@blowgoa ts.com> wrote in message
news:vt******** ****@corp.super news.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********@ver izon.net> wrote in message
news:eX******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a column in my WinGrid, that's being populated with numeric data, but
it's of String datatype(busine ss 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,Col umnName....). 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").Ro ws.Count - 1

If Not dsTyped.Tables( "TableName").Ro ws(iRow)(Column Name) Is
GetType(System. Int32)

ThendsTyped.Tab les("TableName" ).Rows(iRow)(Co lumnName)
= CType(dsTyped.T ables("TableNam e").Rows(iRow)( ColumnName), System.Int32)
End If

Next

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

Thanks, Alex Ayzin


Nov 22 '05 #4

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

Similar topics

3
393
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 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...
3
2715
by: Bern | last post by:
is there some way to convert a hex string to an int and vice versa
1
1035
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
1582
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... instead of 1,2,3... Is there any way to handle this without having to make a sort order column? -- Robert
4
1822
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 maintains this data, I want to ensure that the user cannot type in a value that cannot be converted to the specified
15
8049
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 instead of 06. Thanks a lot.
4
3973
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 value in C-Sharp the easiest way possible. I've tried multiple ways, using ExecuteNonQuery, ExecuteScalar, etc. and I just can't get the value. I've tested the SP in SQL Manager and it returns the value just fine. This is the SP:
0
1120
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 within the DLL I get an Exception HRESULT: 0x8000FFFF (E_UNEXPECTED) According to the Documentation this is a critical error (bleh what else ....), but found no hint on what can cause this behaviour. The Function gets 6 Parameters, a Boolean,...
0
1380
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 this variable .It intializes structure memebers only. I am using Pro*C/C++: Release 8.1.7.0.0 and OS details is : Release: 5.8 Kernel architecture: sun4u Application architecture: sparc Hardware provider: Sun_Microsystems Domain: Kernel version:...
1
2436
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
8036
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, 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...
0
7978
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,...
0
8317
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 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...
0
6796
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3948
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...
0
4010
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2454
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1572
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1313
bsmnconsultancy
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...

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.