0
有誰知道我可以如何將以下字符串轉換爲VB中的DateTime值? 如何將字符串轉換爲datetime? 我的代碼在下面提供,真的很感謝一些幫助。如何從字符字符串轉換日期時間字符串VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
conn = New SqlConnection(connectionstring)
conn.Open()
Dim combo1 As Integer
combo1.ToString("yyyy-MM-dd HH:mm:ss")
combo1 = ComboBox1.SelectedIndex
asd = New SqlCommand("select jam from jadwal where waktu_booking = '" & combo1 & "'", conn)
TextBox7.Text = asd.ExecuteScalar()
adm = New SqlCommand("select tarif from tarif_sewa where kode_tarif = '" & TextBox7.Text & "'", conn)
TextBox2.Text = adm.ExecuteScalar()
conn.Close()
End Sub
我得到了errmsg「從字符串轉換datetime時轉換失敗。」 on TextBox7.Text = asd.ExecuteScalar()
使用'DateTime.ParseExact','DateTime.TryParseExact'等,以將數據轉換爲一個'DateTime' - 但是*不*嵌入在像這樣的SQL值。改用參數化的SQL。 –
http://www.dotnetperls.com/datetime-parse-vbnet – Damith