16.01.2013 Views

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 35: Building Applications Using Windows SharePoint Services Data 983<br />

SQLDataAdapter.SelectComm<strong>and</strong> = & _<br />

New SqlComm<strong>and</strong>(SQLSelectListDetailString, SQLConn)<br />

DiscussionData.Tables.Add("UserData")<br />

SQLDataAdapter.Fill(DiscussionData.Tables("UserData"))<br />

SQLDataAdapter.Dispose()<br />

'<br />

' Capture the total number of entries we found (NOTE: This<br />

' number is also in the Lists Table as column tp_ItemCount,<br />

' but better to use what is returned):<br />

'<br />

TotalItems = DiscussionData.Tables("UserData").Rows.Count<br />

'<br />

' We're done with the data connection so close it:<br />

'<br />

SQLConn.Close()<br />

'<br />

' Now we'll dynamically bind the data to the DataList...<br />

'<br />

' Create a new DataTable <strong>and</strong> create Columns for us to fill:<br />

'<br />

Dim OurDT As New DataTable<br />

Dim OurDRs As Integer<br />

Dim BuildDataRow As DataRow<br />

Dim GetIndex As Integer<br />

'<br />

' Add two columns, Subject title <strong>and</strong> Message<br />

'<br />

OurDT.Columns.Add("Title", GetType(String))<br />

OurDT.Columns.Add("DescText", GetType(String))<br />

'<br />

' Loop through the table <strong>and</strong> build the DataTable:<br />

'<br />

For GetIndex = 0 To (TotalItems - 1)<br />

BuildDataRow = OurDT.NewRow()<br />

BuildDataRow("Title") = & _<br />

DiscussionData.Tables("UserData").Rows(GetIndex).Item("nvarchar1")<br />

BuildDataRow("DescText") = & _<br />

DiscussionData.Tables("UserData").Rows(GetIndex).Item("ntext2")<br />

OurDT.Rows.Add(BuildDataRow)<br />

Next<br />

'<br />

' Now establish a new DataView from the table just created:<br />

'<br />

Dim OurDataView As DataView = New DataView(OurDT)<br />

'<br />

' Bind it to the DataList control <strong>and</strong> we're done!<br />

'<br />

DataList1.DataSource = OurDataView<br />

DataList1.DataBind()<br />

End Sub<br />

End Class<br />

When you are done editing, save your work by pressing Ctrl+S or by selecting<br />

File from the top menu <strong>and</strong> clicking Save ProbSolutionKB.aspx.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!