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

DateTimePicker1的值插入到数据库的问题

helifu 发布于 2006-12-11 16:42, 2462 次点击
我的form中有个DateTimePicker1
我要把DateTimePicker1的输入保存到SQl数据库中去要怎么弄
SQL语句我是知道的,我想知道怎么得到那上面的输入值

12 回复
#2
bygg2006-12-11 17:21
DateTimePicker1.SelectText   或者 DateTimePicker1.Text
#3
helifu2006-12-11 19:42

我写好了SQL语句,在执行时报“从字符串转为Datatime时发生语法错误”

#4
bygg2006-12-11 20:11
两边不要加单引号
#5
helifu2006-12-11 20:22

不是那个问题了,出新问题了
'年12月11日附近有语法错误。'
我的SQL语句: strsql = "update Employees set ELName='" & TextYGXS.Text & "',EFName='" & TextYGXM.Text & "',Address='" & TextDZ.Text & "',City='" & TextSZCS.Text & "',State='" & TextSZSF.Text & "',Zip='" & TextYB.Text & "',Phone='" & TextDH.Text & "',Dob=" & DateTimePicker2.Text & ",Doj=" & DateTimePicker1.Text & ",Designation='" & ComboZW.Text & "',DeptID='" & ComboSSBM.Text & "',Password='" & TEXTMM.Text & "' where EmpID='" & ComboYGID.Text & "'"
麻烦了

#6
bygg2006-12-11 20:52
设置一个断点就知道是哪里的错了.
#7
helifu2006-12-11 21:09

strsql = "update Employees set ELName='" & TextYGXS.Text & "',EFName='" & TextYGXM.Text & "',Address='" & TextDZ.Text & "',City='" & TextSZCS.Text & "',State='" & TextSZSF.Text & "',Zip='" & TextYB.Text & "',Phone='" & TextDH.Text & "',Dob=" & DateTimePicker2.Text & ",Doj=" & DateTimePicker1.Text & ",Designation='" & ComboZW.Text & "',DeptID='" & ComboSSBM.Text & "',Password='" & TEXTMM.Text & "' where EmpID='" & ComboYGID.Text & "'"

Public Function updatedatabase(ByVal SQLcmd As String)
Try
Dim conn As SqlConnection
Dim cmd As SqlCommand
conn = New SqlConnection(Connstr)
conn.Open()
cmd = New SqlCommand(SQLcmd, conn)
cmd.ExecuteNonQuery()在这个地方就跳到下面去了
conn.Close()

Catch ex As Exception
MsgBox(ex.Message)

#8
Viviwei2006-12-11 21:20
DateTimePicker1.value.date
#9
chen53222006-12-12 13:05
Dim cmd As New SqlCommand("select count(*) from c_invoice where inumber='" & TextBox1.Text & "'", conStr)
#10
chen53222006-12-12 13:05
Dim cmd1 As New SqlCommand("update c_invoice set department='" & ComboBox1.Text & "',slid='" & ComboBox2.Text & "',idate='" & dt1.Text & "',mdid='" & ComboBox3.Text & "',iquantity='" & TextBox6.Text & "',money='" & TextBox9.Text & "',uid='" & ComboBox5.Text & "',colorid='" & ComboBox6.Text & "',Payment='" & ComboBox7.Text & "',smid='" & ComboBox8.Text & "',remarks='" & TextBox11.Text & "' where inumber='" & TextBox1.Text & "'", conStr)
#11
不吃→苹果2006-12-23 04:33
全说错了.
是:(DateTimePicker1.Format)
#12
小小兵2006-12-29 23:44
date.parse(DateTimepicker1.text)
#13
haha_orc2010-08-02 11:37
把数据库中对应的改成字符型就ok了用datetime就会报错
1