How do I display 2 places after decimal (currency) when zero reading from Access DB?

Joined
Oct 10, 2005
Messages
7
Programming Experience
Beginner
I want to display 10.50 instead of 10.5 to txtSalesPrice.Text when I read Access DB. It is stored in the DB as a String 10.5. How do I change the code below for txtSalesPrice.Text and txtCost.Text? Thanks in advance for any help.
VB.NET:
[FONT=Verdana][COLOR=green][FONT=Courier New][FONT=Times New Roman]' Display the current record.[/FONT][/FONT][/COLOR][/FONT][FONT=Verdana]
[FONT=Times New Roman][COLOR=blue][FONT=Courier New]Private[/FONT][/COLOR][FONT=Courier New] [COLOR=blue]Overloads[/COLOR] [COLOR=blue]Sub[/COLOR] ShowCurrentRecord([COLOR=blue]ByVal[/COLOR] drCurrent [COLOR=blue]As[/COLOR] DataRow)[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  txtPartNumber.Text = drCurrent.Item("fldPartNumber").ToString[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  txtPartDescription.Text = drCurrent.Item("fldPartDescription").ToString[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  txtQtyOnHand.Text = drCurrent.Item("fldQtyOnHand").ToString[/FONT][/FONT]
 
[FONT=Courier New][FONT=Times New Roman][COLOR=red][B]  txtCost.Text = drCurrent.Item("fldCost").ToString[/B][/COLOR][/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman][COLOR=red][B]  txtSalesPrice.Text = drCurrent.Item("fldSalesPrice").ToString[/B][/COLOR][/FONT][/FONT]
 
[FONT=Courier New][FONT=Times New Roman]  [COLOR=blue]Dim[/COLOR] temp [COLOR=blue]As[/COLOR] [COLOR=blue]Integer[/COLOR] = mintCurrent + 1[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  lblCount.Text = temp.ToString  [COLOR=green]' Current Record Number + 1 [/COLOR][/FONT][/FONT]
 
[FONT=Courier New][FONT=Times New Roman]  lblTotalRecords.Text = dtNames.Rows.Count.ToString[/FONT][/FONT]
[FONT=Times New Roman][COLOR=blue][FONT=Courier New]End[/FONT][/COLOR][FONT=Courier New] [COLOR=blue]Sub[/COLOR][/FONT][/FONT]
 
[COLOR=blue][FONT=Courier New][FONT=Times New Roman]‘ Here I load the data from the DB to the DS. I tried using Currency even though it’s stored as a String in the DB. [/FONT][/FONT][/COLOR]
 
[FONT=Times New Roman][COLOR=blue][FONT=Courier New]Dim[/FONT][/COLOR][FONT=Courier New] odbInsertParamCost [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] _[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  OleDbParameter("fldCost", _[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  OleDbType.Currency, 20, "fldCost")[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman] [COLOR=green]'OleDbType.VarWChar, 20, "fldCost")[/COLOR][/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman] [COLOR=green]'OleDbType.VarWChar,  0, "fldCost")[/COLOR][/FONT][/FONT]
 
 
[FONT=Times New Roman][COLOR=blue][FONT=Courier New]Dim[/FONT][/COLOR][FONT=Courier New] odbInsertParamSalesPrice [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] _[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  OleDbParameter("fldSalesPrice", OleDbType.VarWChar, _[/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman]  20, "fldSalesPrice")[/FONT][/FONT]
 
 
[/FONT]
 
VB.NET:
[FONT=Courier New][FONT=Verdana][FONT=Courier New][FONT=Times New Roman][COLOR=red][B] txtCost.Text = drCurrent.Item("fldCost").ToString(c)[/B][/COLOR][/FONT][/FONT]
[FONT=Courier New][FONT=Times New Roman][COLOR=red][B]  txtSalesPrice.Text = drCurrent.Item("fldSalesPrice").ToString(c)[/B][/COLOR][/FONT][/FONT][/FONT][/FONT]
 
I copied and pasted into Visual Studio and I got the following syntax error on both stmts. I don't know enough to guess at the cause. I have Option Strict On?

"Public Overridable Function ToString() As String' has no parameters and its return type cannot be indexed.

txtCost.Text = drCurrent.Item("fldCost").ToString(c)
txtSalesPrice.Text = drCurrent.Item("fldSalesPrice").ToString(c)
 
dang, that's what i get for answering questions from memory

you could use the FormatCurrency function for this though:
VB.NET:
[B][FONT=Times New Roman][COLOR=#ff0000]txtCost.Text = [U][COLOR=blue]FormatCurrency(drCurrent.Item("fldCost"))[/COLOR][/U][/COLOR][/FONT][/B]
 
Back
Top