03081000104970, 0744,2003-08-10,16:30:13,0,0,1
03081000104971, 1449,2003-08-10,16:30:28,0,0,1
03081000104972, 2409,2003-08-10,17:02:14,0,0,1
03081000104973, 0711,2003-08-10,17:03:33,0,0,1
03081000104974, 0877,2003-08-10,17:30:03,0,0,1
.......
现要求把这些导入到SQ: Server数据库中,要求速度很快。多谢!
问题解决后,马上结贴。请提供代码。
7 个解决方案
#1
用DTS编程吧
#2
开始-〉程序-〉Microsoft SQL Server -> 导入和导出数据 -> 下一步 -〉数据源选择你要导人的文本文件,然后应该会做了吧?
#3
大哥,我要用VB编程来实现啊,用你这种方法,谁不会啊。
#4
字段之间用逗号分隔的,可以把这些字符分隔开,然后再插入数据库,应该不难的.
#5
Dim s As String
Open "e:\test.txt" For Input As #1
While Not EOF(1)
Input #1, s
MsgBox s 'S就是每个字段的值,你可以换成数据库中的字段就行了
Wend
Close #1
Open "e:\test.txt" For Input As #1
While Not EOF(1)
Input #1, s
MsgBox s 'S就是每个字段的值,你可以换成数据库中的字段就行了
Wend
Close #1
#6
Private Function funBulk(strFileName As String, strTable As String, objCn As ADODB.Connection) As Boolean
Dim objcm As New ADODB.Command
objcm.ActiveConnection = cn
objcm.CommandType = adCmdText
'从指定的数据文件中导入Spot,该文件使用竖杠 (|) 字符作为字段终止符,使用 \n 作为行终止符。
objcm.CommandText = "BULK INSERT " & strTable & _
"From '" & strFileName & "'" & _
"WITH " & _
"( " & _
"FIELDTERMINATOR = '|', " & _
"ROWTERMINATOR = '\n'" & _
")"
objcm.Execute
Set objcm = Nothing
End Function
#7
'///////////////改为///////////
Private Function funBulk(strFileName As String, strTable As String, objCn As ADODB.Connection) As Boolean
Dim objcm As New ADODB.Command
objcm.ActiveConnection = cn
objcm.CommandType = adCmdText
'从指定的数据文件中导入Spot,该文件使用竖杠 (,) 字符作为字段终止符,使用 \n 作为行终止符。
objcm.CommandText = "BULK INSERT " & strTable & _
"From '" & strFileName & "'" & _
"WITH " & _
"( " & _
"FIELDTERMINATOR = ',', " & _
"ROWTERMINATOR = '\n'" & _
")"
objcm.Execute
Set objcm = Nothing
End Function
Private Function funBulk(strFileName As String, strTable As String, objCn As ADODB.Connection) As Boolean
Dim objcm As New ADODB.Command
objcm.ActiveConnection = cn
objcm.CommandType = adCmdText
'从指定的数据文件中导入Spot,该文件使用竖杠 (,) 字符作为字段终止符,使用 \n 作为行终止符。
objcm.CommandText = "BULK INSERT " & strTable & _
"From '" & strFileName & "'" & _
"WITH " & _
"( " & _
"FIELDTERMINATOR = ',', " & _
"ROWTERMINATOR = '\n'" & _
")"
objcm.Execute
Set objcm = Nothing
End Function
#1
用DTS编程吧
#2
开始-〉程序-〉Microsoft SQL Server -> 导入和导出数据 -> 下一步 -〉数据源选择你要导人的文本文件,然后应该会做了吧?
#3
大哥,我要用VB编程来实现啊,用你这种方法,谁不会啊。
#4
字段之间用逗号分隔的,可以把这些字符分隔开,然后再插入数据库,应该不难的.
#5
Dim s As String
Open "e:\test.txt" For Input As #1
While Not EOF(1)
Input #1, s
MsgBox s 'S就是每个字段的值,你可以换成数据库中的字段就行了
Wend
Close #1
Open "e:\test.txt" For Input As #1
While Not EOF(1)
Input #1, s
MsgBox s 'S就是每个字段的值,你可以换成数据库中的字段就行了
Wend
Close #1
#6
Private Function funBulk(strFileName As String, strTable As String, objCn As ADODB.Connection) As Boolean
Dim objcm As New ADODB.Command
objcm.ActiveConnection = cn
objcm.CommandType = adCmdText
'从指定的数据文件中导入Spot,该文件使用竖杠 (|) 字符作为字段终止符,使用 \n 作为行终止符。
objcm.CommandText = "BULK INSERT " & strTable & _
"From '" & strFileName & "'" & _
"WITH " & _
"( " & _
"FIELDTERMINATOR = '|', " & _
"ROWTERMINATOR = '\n'" & _
")"
objcm.Execute
Set objcm = Nothing
End Function
#7
'///////////////改为///////////
Private Function funBulk(strFileName As String, strTable As String, objCn As ADODB.Connection) As Boolean
Dim objcm As New ADODB.Command
objcm.ActiveConnection = cn
objcm.CommandType = adCmdText
'从指定的数据文件中导入Spot,该文件使用竖杠 (,) 字符作为字段终止符,使用 \n 作为行终止符。
objcm.CommandText = "BULK INSERT " & strTable & _
"From '" & strFileName & "'" & _
"WITH " & _
"( " & _
"FIELDTERMINATOR = ',', " & _
"ROWTERMINATOR = '\n'" & _
")"
objcm.Execute
Set objcm = Nothing
End Function
Private Function funBulk(strFileName As String, strTable As String, objCn As ADODB.Connection) As Boolean
Dim objcm As New ADODB.Command
objcm.ActiveConnection = cn
objcm.CommandType = adCmdText
'从指定的数据文件中导入Spot,该文件使用竖杠 (,) 字符作为字段终止符,使用 \n 作为行终止符。
objcm.CommandText = "BULK INSERT " & strTable & _
"From '" & strFileName & "'" & _
"WITH " & _
"( " & _
"FIELDTERMINATOR = ',', " & _
"ROWTERMINATOR = '\n'" & _
")"
objcm.Execute
Set objcm = Nothing
End Function