注册 登录
编程论坛 VB.NET论坛

SQL更新时间字段问题

lhj56459897 发布于 2017-08-16 10:14, 1861 次点击
updataStr = "update Table_stockm set " 'set后要留一空格,Table_stockm是一个表
        If Txtpiaoju.Text.Trim <> "" Then
            updataStr = updataStr & "票据号='" & Txtpiaoju.Text.Trim & "',"
        Else
            updataStr = updataStr & "票据号='',"     
       If DateTimePicker1.Text.Trim <> "" Then
            updataStr = updataStr & "进货日期=#" & DateTimePicker1.Text.Trim & "#"‘错误就出在这,进货日期是一个Sql日期型字段(DateTime)
        Else
            updataStr = updataStr & "进货日期=''"
        End If
updataStr = updataStr & " where 票据号='" & Txtpiaoju.Text.Trim & "'"
        Dim Strcon As New SqlConnection(myConn)’myconn是一个字符串,链接数据库的,没有错误
        Strcon.Open()
        Dim mycommand As New SqlCommand(updataStr, Strcon)
         = CommandType.Text
        mycommand.ExecuteNonQuery()‘此处提示错误,=====从字符串转换日期和/或时间时,转换失败。
1 回复
#2
xyxcc1772017-09-13 17:04
将DateTimePicker1.Text.Trim 改为DateTimePicker1.Value.TOString
1