问题描述
我是ashwani,感谢很多帮助我的人...
我在计算机上运行程序,该程序运行时没有任何错误,但是当我在另一台计算机上运行它的EXE时,显示错误消息:"char数据类型的对话导致日期时间值超出范围.单击保存"按钮后,该语句已终止...请帮助我在这里找到我的代码.........
Hi this is ashwani, thanx a lot for helping me .....
I run my program on my computer and it runs without any errors, but when I run its EXE on another computer it shows me the error "the conversation of a char data type resulted in an out-of-range datetime value. This statement has been terminated after clicking the save button...plz help me here''s my code.........
If con.State <> ConnectionState.Open Then
con.Open()
End If
Dim dr As SqlDataReader
Dim cmd As New SqlCommand(" select * from sysobjects where name = 'scan_salary'", con)
dr = cmd.ExecuteReader
If Not dr.HasRows Then
If con1.State <> ConnectionState.Open Then
con1.Open()
End If
Dim cmd1 As New SqlCommand(" create table scan_salary(Image_Id numeric(10,0) identity(1,1),Emp_id numeric(18,0), " & _
"Effect_Date datetime,Salary nvarchar(50),Imagedata image,Insert_Date datetime )", con1)
cmd1.ExecuteNonQuery()
con1.Close()
End If
dr.Close()
If con1.State <> ConnectionState.Open Then
con1.Open()
End If
Dim files() As String
files = Directory.GetFiles(Label4.Text)
Dim insdate, effdate As String
insdate = Now().Date
effdate = dtp1.Value.ToString
Dim emp_id As String = Class2.Empid
Dim sal As String = Class2.salary
Dim imgdata() As Byte = readfile(lbl_path.Text)
Dim CONFIRMATION As DialogResult = MessageBox.Show("are you sure you want to Save the document ?", "The Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If CONFIRMATION = Windows.Forms.DialogResult.Yes Then
Dim cmd6 As New SqlCommand("insert into emp.dbo.scan_salary ( emp_id,salary, imagedata, insert_date, effect_date)" & _
"values ('" & emp_id & "', '" & sal & "',@imagedata, '" & insdate & "','" & effdate & "')", con)
cmd6.Parameters.Add(New SqlParameter("@imagedata", CType(imgdata, Object)))
MsgBox(" Document Saved ")
CheckBox1.Checked = False
End If
推荐答案
Dim insdate, effdate As String
insdate = Now().Date
effdate = dtp1.Value.ToString
不!!!!!!!!!!!
不要那样做.这些是DateTime值.使用适当的数据类型:DateTime.
然后在
NO!!!!!!!!!!!
Do not do that. Those are DateTime values. Use the appropriate data type: DateTime.
And in
Dim cmd6 As New SqlCommand("...
对这两个参数也使用参数值.它将起作用!
also use parameters for these two values. And it will work!
这篇关于字符数据类型的对话导致超出日期时间值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!