Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi I am trying to read from an excel file to my asp.net pages. Everything displays fines except the column the has decimal values in it. In my excel files I am restricting the Cell format to only show 2 decimal but some how when I read this in to my asp page it display all the decimals... I want to truncte the values to 2 decimals only can some one guide me how to do this...the code I using to display an excel file in asp is as follows:
private void Page_Load(object sender, System.EventArgs e)
{
DataSet myDataSet = new DataSet();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\exceltest.xls;" + "Extended Properties=\"Excel 8.0;\"";
OleDbDataAdapter myData = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
myData.TableMappings.Add("Table", "ExcelTest");
myData.Fill(myDataSet);
dgrdSample.DataSource = myDataSet.Tables[0].DefaultView;
dgrdSample.DataBind();
}how can I trucate the output to 2 decimals...I am using C# to code... Will appreciate any help...Thanks

The problem is not with the grid but with the query. Try the select Query as :
'SELECT ROUND(<<COLUMN_NAME>>,2) FROM .... WHERE ....'
Here 2 is the decimal precision (2 digits after the decimal pt).
Regards,
Gaurish

Thanks Gaurish....That was a lot of help....I just had one more question if you could help me out....
'SELECT ROUND(<<COLUMN_NAME>>,2) FROM .... WHERE ....' with this I am only able to select one Column, do you happen to know the syntax to either do all columns from the sheet or do more then one column...Thanks

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |