1,216
社区成员
发帖
与我相关
我的任务
分享
Private Sub testCSV()
Dim TempPath As String
Dim cnn, rs, SqlStr As String, MyArr As Variant
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
TempPath = "D:\"
ConnStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & "DBQ=" & TempPath & "\;Persist Security Info=False;Extended Properties='Text;FMT=Delimited(,);HDR=YES;IMEX=1'"
cnn.Open ConnStr
If cnn.State = 1 Then
SqlStr = "update [TestSql.csv] set [TestQty]='15555'"
' SqlStr = "select * from TestSql.csv"
cnn.Execute SqlStr
' End If
End If
End Sub
update t
set t.IV=t.IV*1.08
FROM (select A.IV from A where A.ID>10) t
Dim i As Long
Dim hFile As Integer
If cnn.State = 1 Then
rs.CursorLocation = adUseClient
rs.Open "select * from [1.csv]", cnn, adOpenDynamic, adLockBatchOptimistic
Set rs.ActiveConnection = Nothing '把rs断开连接,作为一个内存表保留'
cnn.Close '关闭连接,使得下面可以写csv文件'
Set cnn = Nothing
'在内存表中更改TestQty字段只'
While Not rs.EOF
rs!TestQty = 15555
rs.MoveNext
Wend
rs.UpdateBatch
rs.MoveFirst
'重写csv'
hFile = FreeFile()
Open TempPath & "1.csv" For Output Access Write As #hFile
'表头'
For i = 0 To rs.Fields.Count - 1
If i <> 0 Then
Print #hFile, ",";
End If
Print #hFile, rs.Fields(i).Name;
Next
Print #hFile, ""
'数据'
Print #hFile, rs.GetString(columnDelimeter:=",");
Close #hFile
End If