标题: 请帮忙,我按照示例代码试验不成功,帮我测测 [打印本页] 作者: zxh 时间: 2006-4-29 19:12 标题: 请帮忙,我按照示例代码试验不成功,帮我测测 步骤1
用以下代码导出pubs.xml到c:\
Private Sub Command0_Click()
Call Main
End Sub
Public Sub Main()
On Error GoTo ErrorHandler
'recordset and connection variables
Dim rstAuthors As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQLAuthors As String
' Open connection
Set Cnxn = New ADODB.Connection
strCnxn = "rovider=sqloledb;Data Source=127.0.0.1;" & _
"Initial Catalog=Pubs;Integrated Security=SSPI;user id=sa;password="
Cnxn.Open strCnxn
Set rstAuthors = New ADODB.Recordset
strSQLAuthors = "SELECT au_id, au_lname, au_fname, city, phone FROM Authors"
rstAuthors.Open strSQLAuthors, Cnxn, adOpenDynamic, adLockOptimistic, adCmdText
'For sake of illustration, save the Recordset to a diskette in XML format
rstAuthors.Save "c:\Pubs.xml", adPersistXML
' clean up
rstAuthors.Close
Cnxn.Close
Set rstAuthors = Nothing
Set Cnxn = Nothing
Exit Sub
ErrorHandler:
'clean up
If Not rstAuthors Is Nothing Then
If rstAuthors.State = adStateOpen Then rstAuthors.Close
End If
Set rstAuthors = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
'EndSaveVB