Click here to Skip to main content
15,896,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Dim cmdinsert As New SqlCommand("insert into VMIS_30(RptUnitTypeID,Rpt_Unit,YYYYMM,pipno,name1,clt,savings,typ_loan,amt,no_installme,rate_interest,randm_code)values('" + dr("UNITTYPE") + "','" + dr("VPRCID") + "'," + dr("YYYYMM") + ",'" + repipcode + "','" + dr("NAMEOFTHEMEMBER") + "','" + shgcode + "'," + dr("SAVINGS") + ",'" + dr("TYPELOAN") + "'," + dr("AMOUNT") + "," + dr("NOOFINSTALLMENT") + "," + dr("RATEOFINTEREST") + "," + rancode1.ToString() + ")", conDB)

From the above statement i want convert this(" + dr("SAVINGS") + ") from varchar to numeric
here i m getting data from XML file, then i m importing into database. Here the savings field i m getting null value from XML FILE but in the backend(sqlserver) savings field defined as numeric. While i try to insert null value into DB i m getting error (ie., error converting datatype) so i need to convert here from varchar to numeric
Sorry for interrupt
Post solution for this post
Thanks in advance
Posted
Updated 28-Dec-11 20:19pm
v3
Comments
Mehdi Gholam 29-Dec-11 2:10am    
It makes no sense to convert to a number only to convert it back to a string as the SqlCommand take strings.

What is your exact problem?
rajrprk 29-Dec-11 2:21am    
i have updated now
Amir Mahfoozi 29-Dec-11 2:15am    
dr("SAVINGS") will be treated as an integer because there is no quotes around it.
rajrprk 29-Dec-11 2:21am    
ya i have tried that one too (like this '" + dr("SAVINGS") + "'

Try this:
Convert.ToInt32(dr("SAVINGS"))
 
Share this answer
 
Comments
rajrprk 29-Dec-11 2:22am    
While inserting at that time i want to convert that to numeric value
nagendrathecoder 29-Dec-11 2:26am    
Thats what the code will do.
It will convert null value to 0 at the time of inserting.
rajrprk 29-Dec-11 4:10am    
if i use like this " + dr("SAVINGS") + "'i m getting error follows
Input string was not in a correct format
nagendrathecoder 29-Dec-11 4:13am    
use this--> " + Convert.ToInt32(dr("SAVINGS")) + "
nagendrathecoder 29-Dec-11 4:13am    
use this--> " + Convert.ToInt32(dr("SAVINGS")) + "
In case of possible localization problems (different deciaml separators etc) you can also use the TryParse[^] method.

Another possibility is to do the conversion when putting the data into the database, see: CAST and CONVERT[^]
 
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