空值怎么往ACCESS数据库里填写?
我用如下语句生成了一个TXT文件——11.txt,现在想将这个文件里的内容填写到ACCESS数据库里,生成TXT文件时,某些行的固定位置为空值,再输入到数据库的某列(数据类型为双精度数字)时,报“实时错误 3421 数据类型转换错误”,TXT文件报错的行是第35行,请问如何修改?我使用了几种方式写TXT文件,都是当写入空值时报错。方式一:
Print #FileWrite_HB_3, Text2(i_total).Text & " " & b(0) & " " & b(3) & " " & b(4) & " " & b(6) & " " & b(7) & " " & b(10) & " " & "Null" & " " & b(11) & " "
方式二:
Print #FileWrite_HB_3, Text2(i_total).Text & " " & b(0) & " " & b(3) & " " & b(4) & " " & b(6) & " " & b(7) & " " & b(10) & " " & " " & " " & b(11) & " "
方式三:
Print #FileWrite_HB_3, Text2(i_total).Text & " " & b(0) & " " & b(3) & " " & b(4) & " " & b(6) & " " & b(7) & " " & b(10) & " " & " " & b(11) & " "
生成TXT文件语句:
程序代码:
Dim a As String Dim N As Integer, iPos As Integer flag1_HB_3 = False flag2_HB_3 = False FileRead_HB_3 = FreeFile Open (App.Path & "\导出\") & "temp2.txt" For Input As FileRead_HB_3 'Dir1.Path & "\" & "testfile.txt" FileWrite_HB_3 = FreeFile Open (App.Path & "\导出\") & Text2(i_total).Text & ".txt" For Output As FileWrite_HB_3 Do While Not EOF(FileRead_HB_3) Line Input #FileRead_HB_3, temp_HB_3 If (InStr(temp_HB_3, "<") <> 0) Then N = 0 For iPos = 1 To Len(temp_HB_3) If Mid(temp_HB_3, iPos, Len("<=")) = "<=" Then N = N + 1 End If Next b() = Split(temp_HB_3, " ") flag1_HB_3 = True flag2_HB_3 = False If N = 2 And b(8) = "<=" Then Print #FileWrite_HB_3, Text2(i_total).Text & " " & b(0) & " " & b(3) & " " & b(4) & " " & b(6) & " " & b(7) & " " & b(9) & " " & b(11) & " " & "Null" & " " End If If N = 2 And b(9) = "<=" Then Print #FileWrite_HB_3, Text2(i_total).Text & " " & b(0) & " " & b(3) & " " & b(4) & " " & b(6) & " " & b(7) & " " & b(10) & " " & b(13) & " " & b(14) & " " End If If N = 1 And b(9) = "<=" Then Print #FileWrite_HB_3, Text2(i_total).Text & " " & b(0) & " " & b(3) & " " & b(4) & " " & b(6) & " " & b(7) & " " & b(10) & " " & "Null" & " " & b(11) & " " End If If N = 1 And b(8) = "<=" Then Print #FileWrite_HB_3, Text2(i_total).Text & " " & b(0) & " " & b(3) & " " & b(4) & " " & b(6) & " " & b(7) & " " & b(9) & " " & "Null" & " " & "Null" & " " End If End If Loop Close FileRead_HB Close FileWrite_HB
写入数据库语句:
程序代码:
TxtFile = (App.Path & "\导出\") & Text2(i_total).Text & ".txt" '文件文件位置 DbFile = (App.Path & "\" & "variation.mdb") '数据库文件位置 Set myDB = OpenDatabase(DbFile) '打开数据库文件 Set myTB = myDB.OpenRecordset("variation") '打开数据库表1 Open TxtFile For Input As #1 '打开文本文件 Do While Not EOF(1) Line Input #1, StrTemp StrSp = Split(StrTemp, " ") myTB.AddNew myTB.Fields("文件名") = StrSp(0) myTB.Fields("管芯编号") = StrSp(1) myTB.Fields("测试组别") = StrSp(2) myTB.Fields("测试项目") = StrSp(3) myTB.Fields("管脚号") = StrSp(4) myTB.Fields("测试值下限") = StrSp(5) myTB.Fields("测试值") = StrSp(6) myTB.Fields("测试值上限") = StrSp(7) myTB.Fields("单位") = StrSp(8) myTB.Update Loop Close #1 myTB.Close myDB.Close
报错行:
myTB.Fields("测试值上限") = StrSp(7)
txt文件和数据库
11.rar
(17.82 KB)
variation.rar
(1.14 MB)