我使用VS 2012 asp.net web项目和VB.net作为编程语言。
我的表单上有一个textbox
字段,其textmode
属性设置为Date
(Datepicker)。
当我运行以下代码时,我无法检索记录中保存的日期,
Protected Sub Srch_Click(sender As Object, e As EventArgs) Handles Srch.Click
Dim ARTSQLCON As SqlConnection = New SqlConnection("Data Source=EMBRYOLOGIST;Initial Catalog=ARTSQL;Integrated Security=True")
Try
ARTSQLCON.Open()
If Not Len(FilenumSrc.Text) = 0 Then
Dim sqlread = New SqlCommand
sqlread.CommandText = "SELECT Filenum, DOB FROM TblReg WHERE Filenum = " & FilenumSrc.Text
sqlread.Connection = ARTSQLCON
Dim dr As SqlDataReader
dr = sqlread.ExecuteReader
If dr.HasRows Then
dr.Read()
FileNumTxt.Text = dr.Item("Filenum")
DobTxt.Text = dr.Item("DOB")
dr.Close()
End If
End If
Catch ex As Exception
Finally
ARTSQLCON.Close()
End Try
end sub
答案 0 :(得分:1)
Dim dt As DateTime = Convert.ToDateTime(dr.
Item("DOB").ToString())
DobTxt.Text = String.Format("{0:yyyy-MM-dd}", dt)