如何将txt文件中的内容存入SQL数据库

txt文件格式如下:
序号 条码 数量
1 10011 , 12
2 19910 , 11
内容中和空格还不确定。
怎样存入相应的字段内?
谢谢大家了想了很久都没有想出来只好求助了!
Private Sub cmdOKA_Click()
Dim ReadFile As String
Dim FileNum As Long
Static I As Integer
Dim J, K As Integer
FileNum = FreeFile

Open "D:\080616.txt" For Input As FileNum
' K = 1
Do While Not EOF(FileNum)
Line Input #FileNum, ReadFile
Print ReadFile
' If I <> 0 Then Load txtText(I)
'
' txtText(I).Move 135, 200 + 500 * I
' txtText(I).Text = I
' txtText(I).Visible = True

' txtText(I) = txtText(I) & ReadFile

' J = InStr(K, txtText(I).Text, " ")
' Print Left$(txtText(0).Text, J)
' I = I + 1
' K = J
Loop

' J = InStr(J + 3, txtText(0).Text, " ")
' Print Left$(txtText(0).Text, J)
Close #1

End Sub

第1个回答  2008-06-16
/** 导入文本文件
EXEC master..xp_cmdshell 'bcp "dbname..tablename" in c:\DT.txt -c -Sservername -Usa -Ppassword'

/** 导出文本文件
EXEC master..xp_cmdshell 'bcp "dbname..tablename" out c:\DT.txt -c -Sservername -Usa -Ppassword'

EXEC master..xp_cmdshell 'bcp "Select * from dbname..tablename" queryout c:\DT.txt -c -Sservername -Usa -Ppassword'
第2个回答  2008-06-16
用程序一行一行地读取文本文件,然后写入数据库!或者直接导入,但是前提都必须是要有明显的分隔符号本回答被提问者采纳
相似回答