Hi
How do I format a datetime column from a table for display in a textbox. Here's my code
VB Code:
Dim conn As SqlConnection Dim cmd As SqlCommand Dim connstring As String Dim cmdstring As String Dim rowsaffacted As Integer Dim oAdapter As New SqlDataAdapter() Dim oTable As New DataTable() connstring = ConfigurationSettings.AppSettings("connectionstring") conn = New SqlConnection(connstring) Try conn.Open() cmd = New SqlCommand("SELECT * FROM vmvsurvey where id = " & _id.ToString(), conn) lblStatus.Text = "SELECT * FROM vmvsurvey where id = " _ & _id.ToString() oAdapter = New SqlDataAdapter(cmd) oAdapter.Fill(oTable) ' This is where I'm having trouble txtDate.Text = oTable.Rows(0).Item("surveydate") Catch sqlex As SqlException lblStatus.Text = sqlex.ToString() Catch ex As Exception lblStatus.Text = ex.ToString() Finally With conn If .State <> ConnectionState.Closed Then .Close() End If End With conn = Nothing End Try
The date value is currently displayed as 07/02/2003 15:18:00 but I would like it to be displayed as 07/02/03. I tried many formats etc. but can't seem to find the right approach. I can bind the textbox to the datasource so that's already out.
Thanks




Reply With Quote