hi there,

i have an excel sheet and i need to get values from the excel sheet to the mdf file in the visual studio 2008 database.
the value i want to get from the excel file is a accounting value witch is displayed like this $ 67,300.34.
how can i remove the $ mark and the comma and get the double value to be saved in the database.

how can i do this.

below is the code to getting the value from the excel file

String ProductDes = tt.get_Range("b" + r, "b" + r).Text.ToString();

thanxxxxxxxxxxxxx

I believe the proper way to get the value you are looking for is to use the Value2 property of the Excel.Range object. E.g.

String ProductDes = ((double)tt.get_Range("b" + r, "b" + r).Value2).ToString();

Look here for more detail, Excel.Range

It sounds like atomic age has the best answer but another generic way to handle this sort of things, is simply use the String methods, for example in this case Replace, to replace any $s or ,s in a string with "".

this is the function definition from mdsn:

public string Replace(
	string oldValue,
	string newValue
)

so

ProductDes = ProductDes.Replace("$", "");
ProductDes = ProductDes.Replace(",", "");

this may not be ideal if you can simply fetch a numeric value, but its a generic way to handle these types of data cleaning issues.

Now I'm assuming from your code the value is in ProductDes, but if that variable is storing a value it doesn't seem completely well named. From des i expect a textual description.

Mike

this seems to be the way once you have a good string to get a double

double myVal = Convert.ToDouble(strNumber);

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.