Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

using string instead of int

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mavrick_101 - 18 Mar 2008 19:04 GMT
Often in code, when retrieving a value from table where I don't have to do
any math calculations, I store the value in a string variable instead of
converting to an int and then storing in an int variable.

Do you guys see anything wrong with this practice?
Patrice - 18 Mar 2008 19:10 GMT
And the value in the table is ? IMO it's best to always work with the
intended type (that is int if your database column is an int)....

> Often in code, when retrieving a value from table where I don't have to do
> any math calculations, I store the value in a string variable instead of
> converting to an int and then storing in an int variable.
>
> Do you guys see anything wrong with this practice?
Stan - 18 Mar 2008 20:04 GMT
> > Often in code, when retrieving a value from table where I don't have to do
> > any math calculations, I store the value in a string variable instead of
> > converting to an int and then storing in an int variable.
>
> > Do you guys see anything wrong with this practice?

It's an inefficient way to store an integer. A string requires more
memory and requires more complex (compiled) code to handle it.

So it makes no sense to do it just for the sake of it.
Mark Rae [MVP] - 18 Mar 2008 19:24 GMT
> Often in code, when retrieving a value from table where I don't have to do
> any math calculations, I store the value in a string variable instead of
> converting to an int and then storing in an int variable.

I guess there's nothing intrinsically wrong with it, but I can't imagine why
you would want to do this...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Seth Williams - 18 Mar 2008 19:45 GMT
Other than math calculations, sorting will definitely be a problem, since
text is sorted much differently than numbers
For instance 111 will come before 20, when sorting by text

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup

> Often in code, when retrieving a value from table where I don't have to do
> any math calculations, I store the value in a string variable instead of
> converting to an int and then storing in an int variable.
>
> Do you guys see anything wrong with this practice?
mavrick_101 - 18 Mar 2008 20:01 GMT
Just to avoid unneccary Convet.ToInt32, while retrieving from an Int type
column in table.

> Other than math calculations, sorting will definitely be a problem, since
> text is sorted much differently than numbers
[quoted text clipped - 10 lines]
> >
> > Do you guys see anything wrong with this practice?
Lloyd Sheen - 18 Mar 2008 20:45 GMT
> Just to avoid unneccary Convet.ToInt32, while retrieving from an Int type
> column in table.
[quoted text clipped - 16 lines]
>> >
>> > Do you guys see anything wrong with this practice?

General rule of thumb.  Do your database design.  If a field is numeric then
use a number type.  Don't mix presentation and data.  Designing a database
for presentation sake will eventually come back to bite you and it is much
simpler to fix the presentation layer than your data.

LS
mavrick_101 - 18 Mar 2008 21:02 GMT
No, the data in the tables is still <B>int</B> or whatever. I'm talking about
when retrieving in .aspx code.

> > Just to avoid unneccary Convet.ToInt32, while retrieving from an Int type
> > column in table.
[quoted text clipped - 23 lines]
>
> LS
Lloyd Sheen - 18 Mar 2008 21:24 GMT
> No, the data in the tables is still <B>int</B> or whatever. I'm talking
> about
[quoted text clipped - 35 lines]
>>
>> LS

Sorry I am talking about database tables.
LS
Patrice - 19 Mar 2008 10:04 GMT
Humm how do you retrieve the data ? You shouldn't have to convert. You may
want to post a new thread about your original issue...

Actually I never even thought about not having the correct mapping (and I
don't even remember to have heard about doing such a thing)...

It has a potential to cause loads of problem (comparison, sort, type
checking etc...) or at best you'll have to change your code as soon as you
wan't to do actually something with this data + the conversion even if you
have to do one is not that a huge issue...

I would really use the correct mapping between the client side variables and
the server side data. As said earlier I suspect you have an earlier issue
you may want to post about...

--
Patrice

> Just to avoid unneccary Convet.ToInt32, while retrieving from an Int type
> column in table.
Hans Kesting - 19 Mar 2008 10:36 GMT
When your database column has an "int" type, you can easily do
something like:

DataRow dr = MyDataSet.Rows[0];
int i = (int)dr["MyIntColumn"];

but this will fail if there are "null"s in that column (the field will
then contain a DbNull.Value). In that case use this:

int ?i2 = dr["MyIntColumn"] as int?;

Hans Kesting

mavrick_101 explained :
> Just to avoid unneccary Convet.ToInt32, while retrieving from an Int type
> column in table.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.