|
-
Jan 6th, 2003, 03:02 PM
#1
Thread Starter
Member
Round decimal to 2 places in datagrid?[RESOLVED]
I have a OLEDb(access) that I am using w/ an application. The problem is that when the DataAdapter loads the dataset it looks similar to this : 0.684547643434648. How do I get this to round to 0.68. I've tried changing the data type in the XML schema with no luck. Right now it is setup as a decimal. Any ideas?
Last edited by Nintendo_Wizard; Jan 16th, 2003 at 12:26 PM.
-
Jan 6th, 2003, 04:33 PM
#2
Member
in your DataGridColumnStyle under format use :
In case you need to learn about datagrid formatting:
Walkthrough:
http://msdn.microsoft.com/library/de...asicPrimer.asp
Sample App:
http://msdn.microsoft.com/library/en...ormatting.asp?
Eagle Eye
"Programming is easy ... when you are done."
-
Jan 6th, 2003, 08:18 PM
#3
Thread Starter
Member
Thanks for your reply EagleEye! I must not be doing it right, because its not working for me. This is what I tried:
TableStyles --> DataGridTableStyle --> GridColumnStlye--> DataGrid Column stlye--> format --> #.00. After doinf this the datagrid still displays number as .9895656454343444343. What am I missing? Thanks..
Last edited by Nintendo_Wizard; Jan 7th, 2003 at 10:49 AM.
-
Jan 7th, 2003, 03:46 AM
#4
Hyperactive Member
are you using an SQL statement to retrieve the recordset? if so you could use the Format function in the SQL. e.g.:
Code:
strSQLStm = "SELECT Format(ColumnName, '#.00') AS NewcolumnName, OtherColumnName01, OtherColumnName02 " & _
"FROM TableName WHERE ..... ORDER BY ...."
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Jan 8th, 2003, 09:22 AM
#5
Thread Starter
Member
Hey stingrae! Thanks for the advice. How would I apply the SQL statement you gave me in the command text of the OleDataAdapter?
-
Jan 8th, 2003, 04:17 PM
#6
Hyperactive Member
sure:
here's an example from a project of mine.
Code:
lstRate.Items.Clear()
lstPrice.Items.Clear()
lstTax.Items.Clear()
Dim strSQLStm As String
strSQLStm = "SELECT itm_ID, itm_Name, IIf(IsNull([itr_Name]),'[Not Specified]',[itr_Name]) AS Rate, " & _
" Format([itr_Price],'$#,##0.00') AS Price, Format([itr_Tax],'$#,##0.00') AS Tax " & _
"FROM tbl_ItemRate RIGHT JOIN " & _
"(tbl_ItemMaster RIGHT JOIN " & _
"(tbl_PackageMaster " & _
"LEFT JOIN tbl_PackageItems " & _
"ON tbl_PackageMaster.pkg_ID = tbl_PackageItems.pki_Package) " & _
"ON tbl_ItemMaster.itm_ID = tbl_PackageItems.pki_Item) " & _
"ON tbl_ItemRate.itr_ID = tbl_PackageItems.pki_Rate " & _
"WHERE (tbl_PackageMaster.pkg_ID = " & PkgID & ") " & _
"ORDER BY tbl_PackageItems.pki_Order"
Dim cmdItems As New OleDb.OleDbCommand(strSQLStm, gconDatabase)
Dim datItems As OleDb.OleDbDataReader
datItems = cmdItems.ExecuteReader
Do Until datItems.Read = False
lstRate.Items.Add(datItems("Rate"))
lstPrice.Items.Add(datItems("Price"))
lstTax.Items.Add(datItems("Tax"))
Loop
datItems.Close()
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Jan 16th, 2003, 12:25 PM
#7
Thread Starter
Member
THANKS! Your code works great!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|