vb把txt文件数据写入access表中
各位vb高手们,遇到一事,请教一下,我现在需要将一个txt文件写入表中,txt是固定的格式,(一,二,三,四,五,六,1,2,3,4,5,6),前面汉字部分是固定的,数字...
各位vb高手们,遇到一事,请教一下,我现在需要将一个txt文件写入表中,txt是固定的格式,(一,二,三,四,五,六,1,2,3,4,5,6),前面汉字部分是固定的,数字部分长短不固定,每个之间用,隔开了,我现在需要把数字部分的内容写入表中,分别写入六个字段,空位的用空位代替,跪求各位写一下详细代码,感激不尽。成功后给高分。
展开
1个回答
展开全部
'字段没有给出,假定一行内容为描述的一到六,1到6,汉字数字字符数量相等的话:
'Visual Basic 6.0 Code
Sub SaveText(ByVal strFile As String, cnn As ADODB.Connection)
Dim s As String
Dim a() As String
Dim i As Long, j As Long
Open strFile For Binary As #1
s = Space(LOF(1) - 1)
Get #1, , s
Close #1
a = Split(s, ",") '注意你给出的逗号,半全角不同,假定是全角
s = "INSERT INTO table1 (字段名1,字段名2,字段名3,字段名4,字段名5,字段名6) VALUES ("
For i = 6 To 11 '(UBound(a) + 1) / 2 To UBound(a)
s = s & a(i)
If i < 11 Then s = s & ","
Next i
s = s & ")"
cnn.Execute s
End Sub
'Visual Basic 6.0 Code
Sub SaveText(ByVal strFile As String, cnn As ADODB.Connection)
Dim s As String
Dim a() As String
Dim i As Long, j As Long
Open strFile For Binary As #1
s = Space(LOF(1) - 1)
Get #1, , s
Close #1
a = Split(s, ",") '注意你给出的逗号,半全角不同,假定是全角
s = "INSERT INTO table1 (字段名1,字段名2,字段名3,字段名4,字段名5,字段名6) VALUES ("
For i = 6 To 11 '(UBound(a) + 1) / 2 To UBound(a)
s = s & a(i)
If i < 11 Then s = s & ","
Next i
s = s & ")"
cnn.Execute s
End Sub
追问
我试试看,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询