我遇到的问题是我在datagridview中的出生日期是默认时间12点, 但我的访问日期类型是" dateofbirth"仅设置为"短日期"
我怎样才能在datagridview中显示短日期的出生日期?
这是我的datagridview编码。
Public Sub LoadDGV()
Dim SqlQuery As String = "Select * from userss where delete = no"
Dim SqlCommand As New OleDbCommand
Dim SqlAdapter As New OleDbDataAdapter
Dim table As New DataTable
With SqlCommand
.CommandText = SqlQuery
.Connection = conn
End With
With SqlAdapter
.SelectCommand = SqlCommand
.Fill(table)
End With
DataGridView1.Rows.Clear()
For i = 0 To table.Rows.Count - 1
With DataGridView1
.Rows.Add(table.Rows(i)("studentID"), table.Rows(i)("full_name"), table.Rows(i)("password"), table.Rows(i)("course"), table.Rows(i)("dateofbirth"), table.Rows(i)("gender"), table.Rows(i)("imail_address"), table.Rows(i)("tel_no"), table.Rows(i)("handphone_no"))
End With
Next
End Sub
答案 0 :(得分:2)
使用DefaultCellStyle.Format。 “d”将为您提供短期格式
MyDatagridview.Columns("columnName").DefaultCellStyle.Format = "d"
这里是一些Standard formats格式化字符串。
答案 1 :(得分:1)
而不是
table.Rows(i)("dateofbirth")
您可以使用
table.Rows(i)("dateofbirth").ToShortDateString