Solved

How to convert smallint to int

Posted on 2006-06-08
5
2,217 Views
Last Modified: 2007-12-19
How do you convert a sql server defined field smallint to a int? Fields UnitsOnOrder and UnitsInStock are defined as smallint in sql server.  I get an error using the "Convert.ToInt16".

int intUnitsOnOrder;
int intUnitsInStock;
TextBox txtUnitsInStock = (TextBox)e.Item.Cells[4].Controls[0];
TextBox txtUnitsOnOrder = (TextBox)e.Item.Cells[5].Controls[0];
intUnitsOnOrder = Convert.ToInt16(txtUnitsOnOrder.ToString());  ???? error

 

0
Comment
Question by:Hojoformo
  • 3
5 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 500 total points
ID: 16866906
try this:

intUnitsOnOrder = Int16.Convert(txtUnitsOnOrder.Text);  

AW
0
 
LVL 16

Expert Comment

by:Edwin_C
ID: 16867051
It should be

intUnitsOnOrder = Convert.ToInt16(txtUnitsOnOrder.Text);  
0
 
LVL 16

Expert Comment

by:Edwin_C
ID: 16867054
oops, it should be

intUnitsOnOrder = Convert.ToInt32(txtUnitsOnOrder.Text);  

because you need an int type.
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16867330
Hi,
u can try like this
int a;
            
a=int.Parse(TextBox1.Text);

Regards
Pradeep
0
 
LVL 16

Expert Comment

by:Edwin_C
ID: 16898999
Hi hojoformo

May I know what kind of language you are using?  I thought you are using C# but there should be no Int16.Convert().  Are you sure it works for you?

Edwin
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now