如何在Access数据库中插入空白数据 [英] How to insert blank data in access db
本文介绍了如何在Access数据库中插入空白数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个应用程序,在该应用程序中,我必须记录特定日期范围内完成的交易的报告
为此,我正在创建一个临时表,在表单加载期间将数据插入并读取其中,这是代码
Hi Everyone,
I have an application in which i have to take reports of the transaction done on particular date range
For this I am creating one temp table in which data is inserted and fetched during form load, here is the code
Dim InDate As String
Dim OutDate As String
Dim DtIn As Date
Dim DtOut As Date
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Regno = ds.Tables(0).Rows(i)(0).ToString()
barcode = ds.Tables(0).Rows(i)(1).ToString()
vehityp = ds.Tables(0).Rows(i)(2).ToString()
vehimodl = ds.Tables(0).Rows(i)(3).ToString()
InDate = ds.Tables(0).Rows(i)(4).ToString()
OutDate = ds.Tables(0).Rows(i)(5).ToString()
DtIn = DateTime.Parse(InDate)
DtOut = DateTime.Parse(OutDate)
diff = DtIn - DtOut
DiffD = diff.Days
DiffH = diff.Hours
DiffM = diff.Minutes
Try
sqlcmd = "Insert Into tmp ([RegistrationNo],[Barcode],[VehicleType],[VehicleModel] , [TranInDate], [TranOutDate], [OutDays], [OutHours], [OutMins]) Values ('" _
+ Regno + "','" + barcode + "','" + vehityp + "','" + vehimodl + "', '" + InDate.ToString() + "', '" + OutDate.ToString() + "', " + DiffD.ToString() + ", " + DiffH.ToString() + ", " + DiffM.ToString() + ")"
cmd.CommandText = sqlcmd
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, "Messageinst")
End Try
Next
当我的InDate为空白时,显示错误为
无法将字符串识别为有效的DateTime"
谁能帮助我如何插入空白的InDate值
When My InDate is blank it is showing an error as
"String was not recognised as a valid DateTime"
Can anyone help me on how to insert the blank InDate value
推荐答案
这不是传递参数的最有效方法.使用参数化查询,这是一个示例:
http://www.vb-helper.com/howto_net_db_parameterized_query.html [
This is not the most efficient way of passing parameters. Use parameterized queries, here is an example:
http://www.vb-helper.com/howto_net_db_parameterized_query.html[^]
这篇关于如何在Access数据库中插入空白数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文