从日期/时间vb.net中删除时间

从日期/时间vb.net中删除时间,vb.net,winforms,datetime,textbox,Vb.net,Winforms,Datetime,Textbox,textbox5应该只显示日期,但当我单击按钮时,textbox5会显示日期和时间。ex:12/01/12上午12:00 如何删除显示在文本框中的时间?试试 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form2.Show() Form2.TextBox1.Text = dgv1.CurrentRow.Cel

textbox5应该只显示日期,但当我单击按钮时,textbox5会显示日期和时间。ex:12/01/12上午12:00

如何删除显示在文本框中的时间?

试试

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Form2.Show()

    Form2.TextBox1.Text = dgv1.CurrentRow.Cells(0).Value.ToString
    Form2.TextBox2.Text = dgv1.CurrentRow.Cells(1).Value.ToString
    Form2.TextBox3.Text = dgv1.CurrentRow.Cells(2).Value.ToString
    Form2.TextBox4.Text = dgv1.CurrentRow.Cells(3).Value.ToString
    Form2.TextBox5.Text = dgv1.CurrentRow.Cells(4).Value.ToString
    Form2.TextBox6.Text = dgv1.CurrentRow.Cells(5).Value.ToString
    Form2.TextBox7.Text = dgv1.CurrentRow.Cells(6).Value.ToString

有一个datetime格式函数。选中此项,因为CurrentCells(4)是一个对象。请尝试将其强制转换为日期时间,然后使用

或者,如果转换成功,则可以使用返回true的

Form2.TextBox5.Text = CType(dgv1.CurrentRow.Cells(4).Value, DateTime).ToShortDateString

我刚刚删除了此行中的.ToString:

Dim tempDate As Date
If DateTime.TryParse(CStr(dgv.CurrentRow.Cells(4).Value), tempDate) Then
    Form2.TextBox5.Text = tempDate.ToShortDateString
Else
    Form2.TextBox5.Text = "Invalid Date"
End If
当我删除.ToString时,它只是在日期文本框中显示较短的日期

Form2.TextBox5.Text = dgv1.CurrentRow.Cells(4).Value.ToString

它显示错误:从字符串“mm/dd/yyyy”转换为类型“Integer”无效。确定。。。单元格值的数据类型是什么?它是日期/时间类型,我使用access作为数据库我只想在我从access数据库检索数据时在文本框中显示日期,所以你的意思是它将null视为日期?为什么在从数据库检索到一行之前要让它设置内容?如果这是唯一的问题,请将行包装在
中,如果dgv1.CurrentRow.Cells(4).值不是空的
<代码>如果结束-但这不是正确的方法。只有当你有一条记录可以使用时,你才应该调用显示代码。我已经尝试了该页面的示例,但仍然不起作用
Form2.TextBox5.Text = dgv1.CurrentRow.Cells(4).Value.ToString
declare MyTime as datetime
Mytime  =  dateadd(day, -datediff(day, 0, Date.now), Date.now)