我的MySQL数据库我有一个日期列和一个时间列。使用这些值时,我在VisualBasic中使用正确的格式有很多问题。我知道有很多可能性,但我只试了5个小时,并且找不到适合我的方法。
这是数据库:
这是Vb.net代码:
Imports MySql.Data.MySqlClient
Public Class ShowTermine
Private Sub ShowTermine_Load(sender As Object, e As EventArgs) Handles MyBase.Activated
Dim conn As MySqlConnection
conn = New MySqlConnection("server=server.org;Port=3306; userid=userid; password=password; database=database")
Try
Dim command As New MySqlCommand
Dim sqlquery As String = "SELECT * from bsp_termin WHERE userid =" & Form1.userID(Form1.Select1)
Dim adapter As New MySqlDataAdapter
Dim data As MySqlDataReader
Dim counter As Integer = 0
Dim mydate As Date
conn.Open()
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
While data.Read
Me.TextBox1.Text += data(2).ToString("dd//MM//yyyy")
Me.TextBox1.Text += Environment.NewLine
Me.TextBox2.Text += data(3).ToString
Me.TextBox2.Text += Environment.NewLine
Me.TextBox3.Text += data(4).ToString
Me.TextBox3.Text += Environment.NewLine
End While
data.Close()
conn.Close()
Catch ex As Exception
MsgBox(Err.Number & " " & Err.Description)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Hide()
Form2.Show()
End Sub
End Class
如果我使用TextBox1中的普通字符串,则显示日期,例如2017-09-03。但我需要dd / mm / yyyy格式。所以Me.TextBox1.Text + = data(2).ToString(" dd // MM // yyyy")给出错误。我也尝试过使用CDate,但无法找到合适的格式。
如何在ListBox1中显示日期格式为" 03.09.2017"和TextBox3中的时间字段为" 14:30" (hh / mm)?