Computing.Net > Forums > Programming > ASP.net DataGrid Display!!!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ASP.net DataGrid Display!!!

Reply to Message Icon

Name: Jay_0901
Date: March 22, 2005 at 09:07:52 Pacific
OS: Win XP SP 2
CPU/Ram: P4 3.0 Ghz/ 512 MB
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: bugsvoid
Date: March 23, 2005 at 02:59:50 Pacific
Reply:

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



0

Response Number 2
Name: Jay_0901
Date: March 23, 2005 at 13:34:09 Pacific
Reply:

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



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: ASP.net DataGrid Display!!!

array of controls in asp.net www.computing.net/answers/programming/array-of-controls-in-aspnet/10653.html

Exec. of Web controls in ASP.NET www.computing.net/answers/programming/exec-of-web-controls-in-aspnet/6647.html

ASP.Net in C# and IIS 5.1 www.computing.net/answers/programming/aspnet-in-c-and-iis-51/10312.html