Formatting Data in Dataset.

  • Thread starter Thread starter jayuya
  • Start date Start date
J

jayuya

Can anyone give a sample code, tip, or a web link with an
example of how to format data to currency. eg: $3451.25

I set a dataadapter and I fill the dataset from a SQL
Statement, but some fields are a double data type and I
need to display those fields to the user in currency
format...

I am using ASP.NET/VB.NET/ADO.NET

here is what i got so far...

Dim sql As String
Dim DB As New ADO_Net()

sql="select id, name, AmtOne,AmtTwo from myTable;"

'open database connection
DB.OpenConn()
' Load the dataset
DB.SetDataAdapter(sql, "myTable")

' Get the table from the dataset
Dim DataTable As DataTable = DB.DtSet.Tables(0)

Dim i As Integer
For i = 0 To DataTable.Rows.Count - 1

'need to format fields in currency
'before i display into the PDF document

'the DisplayReportRow function
'draws a string with all the columns
'into the pdf documents but
'I need to format some fields like Currency
Call DisplayReportRow(DataTable.Rows(i))

Next i

DB.DataAdapter.Dispose() 'close data set
DataTable.Dispose() 'close data table
DB.CloseConn() 'close database connection

'end of code

thanks,
jayuya
 
What i like to do is to format the data directly in your SQL statement
instead of in the the application. What kind of database are you
working with?

In SQL-Server you can use '$' + CONVERT(varchar, SomeMoneyValue, 3)

In Access there is a Format function to do this
 
Back
Top