locked
retrieve short date from oracle database RRS feed

  • Question

  • User-194972431 posted

    I have an asp.net page that has a datagrid. I just do "select *" from a table in the oracle database and display all the columns in the grid. 

    The date column (one of the columns in the oracle table) has datatype "date". The problem is: When is get date in the grid, it shows time (like 08/01/2011 12:00:00AM) . I do not want to do a to_char() on the date_column in my select statement because there are too many columns and its easy to just do a "select *"

    Any help .....greatly appreciated!! thanks in advance!

    Friday, August 5, 2011 10:53 PM

Answers

  • User-1412735316 posted

    I thing the best idea would be get the data formatter from oracle though you have to mention all the columns in the select list.

    Or you may use view as suggested. In that case you have to write the query once.

    Formating gridview or datatable will cost valuable execution time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2011 1:33 PM

All replies

  • User-1412735316 posted

    you can use DataFormatString at column definition.

    example:

    <asp:BoundField DataField="SaleDate" HeaderText="OrderDate" SortExpression="SaleDate" DataFormatString="{0:d}"/>

    Saturday, August 6, 2011 3:00 AM
  • User-194972431 posted

    I do not want to define any columns in the data grid because they may vary depending on the user selection. Any other ideas please!

    Saturday, August 6, 2011 11:38 AM
  • User269602965 posted

    Create an Oracle View with your date formatting (you can use TRUNC function to remove time)

    and then do Select * on the VIEW

    Saturday, August 6, 2011 12:31 PM
  • User-1412735316 posted

    you can find which columns are type of date time with something like this

    if(dataTable.Columns[0].DataType.FullName == "System.DateTime")

    you may use rowdatabound event of gridview to format that column with the index from datatable. Though it's not semmingly good solution.


    Saturday, August 6, 2011 1:28 PM
  • User-1412735316 posted

    I thing the best idea would be get the data formatter from oracle though you have to mention all the columns in the select list.

    Or you may use view as suggested. In that case you have to write the query once.

    Formating gridview or datatable will cost valuable execution time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2011 1:33 PM