2 Replies - 4890 Views - Last Post: 04 January 2013 - 01:30 PM Rate Topic: -----

#1 haseeb755  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-December 12

Read data from sql to .net

Posted 03 January 2013 - 02:04 AM

hi
I have a query which reads data from MS SQL TABLE and shows it on aspx page. There is a field in table which data type is DATE, but when it got displayed on aspx page ,it showed up as DATETIME.

here is my code

    Shared Function Get_Leave_History(ByVal employee_name As String) As DataTable
        Dim dbCon As New DBConn()
        Dim str As String = "select [leave_type] as [Leave Type],[from_date] as [From Date],[to_date] as [To Date],[Contact_Number] as [Contact Number],[Address] ,[remarks] ,[Status] from leave where employee_id in (select employee_id from employee where username='" + employee_name + "')"
        Dim DS As New DataSet

        dbCon.Open()
        dbCon.FillDataSet(DS, "Data", str)
        dbCon.Close()

        Return DS.Tables("Data")
    End Function 


Is This A Good Question/Topic? 0
  • +

Replies To: Read data from sql to .net

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: Read data from sql to .net

Posted 03 January 2013 - 11:01 AM

.net has no "Date" data type, you'll need to format the value to exclude the time stamp. How you do that will depend on what control you're using to display the data. If you're using a GridView and it's a boundfield then you could use the following:

<asp:Boundfield DataFormat="{0:d}" ...(rest of code) />


Was This Post Helpful? 1
  • +
  • -

#3 haseeb755  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-December 12

Re: Read data from sql to .net

Posted 04 January 2013 - 01:30 PM

THNAKS
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1