使用vb.net重新获取Sharepoint列表数据

时间:2017-08-22 10:31:46

标签: vb.net sharepoint-2013

我想使用VB.NET检索SharePoint列表数据。

以下代码仅供参考: -

Public Const roleGuid As String = "{8405ef03-40fl-4fan-8dl2-cf7kll1b8c1e}"
Public Const sharepointSite As String = "https://mysharepointsite.com/sites/resourceview.aspx"

Public Function getSharepointList()

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConn As String
Dim sSql As String

sConn = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=1;RetrieveIds=Yes;" & _
"DATABASE=" & sharepointSite & ";" & _
"LIST=" & roleGuid & ";"

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

With cn
    .ConnectionString = sConn
    .Open
End With

sSql = "SELECT * FROM [Student list] as [Student List];"

rs.Open sSql, cn, adOpenStatic, adLockOptimistic

ThisWorkbook.Worksheets("Sheet1").Range("A2").CopyFromRecordset rs


End Function

下面是获取弹出窗口的错误截图

enter image description here

任何方法或建议都会有所帮助。

1 个答案:

答案 0 :(得分:0)

我找到了一种使用vb.net从SharePoint列表中检索数据的方法

Public Function retrieveData()
        'ADD FOLLOWING REFERENCES:-
        'Microsoft ActiveX Data Objects 2.8 Library

        'DECLARING CONNECTION AND RECORDSET OBJECTS, SQLQUERY STRING VARIABLE.
        Dim cnt As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim sqlQuery As String

        'SETTING UP CONNECTION AND RECORDSET OBJECTS.
        cnt = New ADODB.Connection
        rs = New ADODB.Recordset

    'HERE STUDENT LIST IS YOUR SHAREPOINT LIST NAME.
        sqlQuery = "Select * from [Student List];"

        'SETTING CONNECTION STRING TO CONNECTION OBJECT AND OPENING CONNECTION.
        With cnt
            .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=2;RetrieveIds=Yes;DATABASE=https://mysharepointlist.com/sites/;LIST={Your List GUID};"
            .Open()
        End With

        'OPENING RECORDSET.
        rs.Open(sqlQuery, cnt, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly)

     'FILLING DATATABLE WITH THE HELP OF DATA ADAPTER.      
     Dim myDa As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
        Dim myDs As DataTable = New DataTable
        myDa.Fill(myDs, rs)

    'FILLING DATAGRIDVIEW WITH DATATABLE AS DATASOURCE.
    DataGridView1.Datasource = myDs

        'CHECKS IF CONNECTION OBJECTS AND RECORDSET OBJECT IS IN OPEN STATE IF YES THEN IT WILL CLOSE AND DEREFERENCE THEM.
        If CBool(rs.State And ADODB.ObjectStateEnum.adStateOpen) = True Then rs.Close()
        rs = Nothing

        If CBool(cnt.State And ADODB.ObjectStateEnum.adStateOpen) = True Then cnt.Close()
        cnt = Nothing
    End Function