• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2517
  • Last Modified:

How to convert smallint to int

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
Hojoformo
Asked:
Hojoformo
  • 3
1 Solution
 
Arthur_WoodCommented:
try this:

intUnitsOnOrder = Int16.Convert(txtUnitsOnOrder.Text);  

AW
0
 
Edwin_CCommented:
It should be

intUnitsOnOrder = Convert.ToInt16(txtUnitsOnOrder.Text);  
0
 
Edwin_CCommented:
oops, it should be

intUnitsOnOrder = Convert.ToInt32(txtUnitsOnOrder.Text);  

because you need an int type.
0
 
pradeepsudharsanCommented:
Hi,
u can try like this
int a;
            
a=int.Parse(TextBox1.Text);

Regards
Pradeep
0
 
Edwin_CCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now