Private Sub Command2_Click() '*** 处根据实际情况填写 On Error GoTo Handlle Dim s As String Dim c() As String Dim i As Integer Dim strSQL As String Dim cn As New ADODB.Connection cn.ConnectionString = "" '*** cn.Open cn.BeginTrans Open "c:\test.txt" For Input As #1 Do While Not EOF(1) Line Input #1, s c = Split(s, " ") '*** strSQL = "insert into tablename values (" '*** For i = 0 To UBound(c) strSQL = strSQL & "'" & c(i) & "'" & "," '*** Next strSQL = Left(strSQL, Len(strSQL) - 1) & ")" cn.Execute strSQL Loop Close #1 cn.CommitTrans cn.Close Exit Sub Handlle: Close #1 cn.RollbackTrans cn.Close MsgBox Err.Description, vbInformation End Sub
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
'*** 处根据实际情况填写
On Error GoTo Handlle
Dim s As String
Dim c() As String
Dim i As Integer
Dim strSQL As String
Dim cn As New ADODB.Connection
cn.ConnectionString = "" '***
cn.Open
cn.BeginTrans
Open "c:\test.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, s
c = Split(s, " ") '***
strSQL = "insert into tablename values (" '***
For i = 0 To UBound(c)
strSQL = strSQL & "'" & c(i) & "'" & "," '***
Next
strSQL = Left(strSQL, Len(strSQL) - 1) & ")"
cn.Execute strSQL
Loop
Close #1
cn.CommitTrans
cn.Close
Exit Sub
Handlle:
Close #1
cn.RollbackTrans
cn.Close
MsgBox Err.Description, vbInformation
End Sub