试试改成这样
Dim text_shuru As WinForm.TextBox = e.Form.Controls("text_saomiao")
If e.Keycode=13 AndAlso text_shuru.text <> Nothing Then
Dim fdr As DataRow = DataTables("扫描临时表").find("二维码字符串='" & text_shuru.text & "'", "录入时间 DESC")
If fdr IsNot Nothing Then
Dim shijiancha As TimeSpan
Dim kaishijianjian As Date=fdr("录入时间")
shijiancha = Date.Now - kaishijianjian
If shijiancha.TotalSeconds < 10 Then '如果这段不执行的话就不会报错!
MessageBox.Show("为了防止重复录入,同一个二维码的扫描时间必须大于10秒")
Return
End If
End If
Dim nr As Row = Tables("扫描临时表").AddNew
nr("二维码字符串")= text_shuru.text
nr("录入时间")=Date.Now
Dim Values() As String
values=text_shuru.text.Split(" ")
If values.Length<>6 Then
MessageBox.Show("您扫描的二维码是未知的,请核对后再试")
Else
Dim cmd As new SQLCommand
cmd.ConnectionName = "数据源"
cmd.CommandText="查询语句省略..."
Dim shangpingdangan As String = cmd.ExecuteScalar
With Tables("采购到货")
.AddNew()
.Current("存货编码")=values(0)
.Current("采购单号")=values(1)
.Current("供应商代码")=values(2)
.Current("生产周期")=values(3)
.Current("生产批次")=values(4)
.Current("数量")=values(5)
.Current("扫描时间")=Date.Now
.Current("存货名称")=shangpingdangan
.Current("已入ERP")=0
.DataTable.Save
End With
text_shuru.Value=Nothing
End If
End If