正确的显示和编辑日期的方式

时间:2017-11-24 15:01:23

标签: sql-server vb.net

我在文本框中的表单中显示数据库中的日期,但数据库中日期的格式为mm/dd/yyyy如何以yyyy-mm-dd格式显示。

可以将我的日期格式编辑为mm/dd/yyyy吗?

这是我的代码:

Dim search As String = String.Empty
    search &= "select * from stocks "
    search &= "where build_number=@build"

    If ebuildnumber.Text = "" Then
        MsgBox("Please Input Build Number Before Searching")
    End If

    Using conn As New SqlConnection("server=WIN10;database=pc_parts;user=admin;password=12345;")
        Using cmd As New SqlCommand
            With cmd
                .Connection = conn
                .CommandType = CommandType.Text
                .CommandText = search
                .Parameters.AddWithValue("@build", ebuildnumber.Text)
            End With

            Try
                conn.Open()
                Dim reader As SqlDataReader = cmd.ExecuteReader
                If reader.HasRows Then
                    With reader
                        reader.Read()
                        ebrand.Text = .GetValue(1)
                        epart.Text = .GetValue(2)
                        equantity.Text = .GetValue(3)
                        edate.Text = .GetValue(4)
                        reader.Close()
                    End With
                Else
                    MsgBox("Build Number Not Found")
                End If
                conn.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Using
    End Using

End Sub

0 个答案:

没有答案