把EXCEL作为数据库,只能查询不能插入删除吗?
1.查询 select,这个能做到
2.执行delete与报错,说无法删除.
源码如下:
Private Sub Command1_Click()
Dim i As Integer
Dim strPid As String
StrConnForXLS1 = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=SFCName_V230.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
StrConnForXLS2 = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=Book1.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
ConnForXLS1.ConnectionString = StrConnForXLS1
ConnForXLS2.ConnectionString = StrConnForXLS2
ConnForXLS1.Open
ConnForXLS2.Open
RSForXLS1.Open "Select * from [Sheet1$] where Pid<>''", ConnForXLS1, 1, 3
RSForXLS1.MoveFirst
Do Until RSForXLS1.EOF
strPid = RSForXLS1("Pid")
RSForXLS2.Open "Select * from [Sheet1$] where PID='" & strPid & "'", ConnForXLS2, 1, 3
If RSForXLS2.RecordCount = 0 Then
ConnForXLS1.Execute "delete from [Sheet1$] where Pid='" & strPid & "'"
End If
RSForXLS1.MoveNext
Loop
RSForXLS1.Close
RSForXLS2.Close
ConnForXLS1.Close
ConnForXLS2.Close
End Sub
1.查询 select,这个能做到
2.执行delete与报错,说无法删除.
源码如下:
Private Sub Command1_Click()
Dim i As Integer
Dim strPid As String
StrConnForXLS1 = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=SFCName_V230.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
StrConnForXLS2 = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=Book1.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
ConnForXLS1.ConnectionString = StrConnForXLS1
ConnForXLS2.ConnectionString = StrConnForXLS2
ConnForXLS1.Open
ConnForXLS2.Open
RSForXLS1.Open "Select * from [Sheet1$] where Pid<>''", ConnForXLS1, 1, 3
RSForXLS1.MoveFirst
Do Until RSForXLS1.EOF
strPid = RSForXLS1("Pid")
RSForXLS2.Open "Select * from [Sheet1$] where PID='" & strPid & "'", ConnForXLS2, 1, 3
If RSForXLS2.RecordCount = 0 Then
ConnForXLS1.Execute "delete from [Sheet1$] where Pid='" & strPid & "'"
End If
RSForXLS1.MoveNext
Loop
RSForXLS1.Close
RSForXLS2.Close
ConnForXLS1.Close
ConnForXLS2.Close
End Sub