Hello guys,
I have a problem with data type.I want to store a field with a currency format in access with vb.net.i did it by using the format built-in function in vb.net but it only stores the field in access if it's only in text data-type.If the field is in number format it would result in data type mismatch.

what is the solution for this?

Recommended Answers

All 7 Replies

Format is a string function. Since it returns a text string, your problem is probably somewhere else. Either in the format you're using, or the data type the database expects, isn't what you think it is.

Yes my datatype in the database is of text datatype.you can store the field in the desired way using the format property.but what i wanted is that i want to make the datatype to number and store the field in a way that i showed you in previous code or using access.

The thing is that currency is not a datatype that I'm aware of. Usually all currency means is a string representation of the number with a currency denomionation symbol in front and thousands separators if necessary. To store a number as currency use the .ToString method and set the format there.

Label12.Text = bridgeasset.ToString("c")

This will format the string as currency specific to the locale of the computer. For me the string is "$1,234.56".

If I understand what you want, it's pretty much impossible to display a number as currency without converting it to a string. A number only contains digits and decimal. As soon as you want anything else in there, it has to become a string.

You are right,currency is not a datatype,ist's a format.now you are getting my idea.i want a number to both be stored with a specific format,currency format in the db either set the format from excel or from the code level.
finally i would use it in crystal reports for total calculation using "sum".

We seem to be going in circles. Do you want an indication in the database when the number is supposed to represent currency so that you can supply the proper formatting when you read/write it? Or do you want to be able to parse the currency string to return a number to use in calculations?

my intention is your first question

You'll probably have to add a boolean flag tied to that field. If it's true format as currency, if it's false format as double.

You could also try creating a custom data-type, something along the lines of the return type being double and the tostring returning a currency format. The code is easy, but I'm not sure about adding it to your database.

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.