Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi to all!

i define a variable "numeric" type in sql server

now when i want to read it in c sharp like

to read "int" in this way
(stingbuilder sb.Append(((int)rdr["mrfno_nu"]).ToString());

and "string" in this way
(stingbuilder sb.Append(((string)rdr["mrfno_nu"]).ToString());


so how to read numeric type
Posted

Take a look on this table

http://msdn.microsoft.com/en-us/library/cc716729.aspx[^]


Cheers!
 
Share this answer
 
Use decimal:
(decimal) rdr["mrfno_nu"]
 
Share this answer
 
using System.Text;
//firs import the above namespace
        
        
        StringBuilder sb=new StringBuilder();

//to read "int" in this way 
         sb.Append(Convert.ToInt32(rdr["mrfno_nu"].ToString()));

//and "string" in this way
         sb.Append(Convert.ToString(rdr["mrfno_nu"].ToString()));


Hope it will help you.
 
Share this answer
 
Comments
fcronin 15-Jul-11 19:25pm    
Closest to what I would do... except in my experience, I haven't had to convert the field value ToString()... just used int Value = Convert.ToIn32(rdr["mrfno_nu"]);
We have 'Decimal' in C# equivalent to numeric in SQL
 
Share this answer
 
Use Decimal or Nullable<Decimal> depending on the situation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900