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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

The next bit of code is all added:<br />

■ We add a local reference to the System.Data.SqlClient namespace so that we<br />

can access the database.<br />

■ We add a subroutine to h<strong>and</strong>le populating the database.<br />

■ We add a call to the subroutine in the Page_Load subroutine to execute it when<br />

the page loads.<br />

Using the following sample code, type in the code shown in boldface type.<br />

We’ve commented each section so that you can follow it:<br />

GUIDGUIDGUIDGUID' ADDED for access to the SQL Database<br />

Imports System.Data.SqlClient<br />

Public Class ProbSolutionKB<br />

Inherits System.Web.UI.Page<br />

+ #Region " Web Form Designer Generated Code "<br />

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)<br />

H<strong>and</strong>les MyBase.Load<br />

'Put user code to initialize the page here<br />

'<br />

' If this was only to load once, then you can uncomment<br />

' the IF statement; without this, the page will reload<br />

' each time (this means added items will be found on refresh):<br />

'<br />

Dim AGUIDInStringFormat As String = "{CD68E7BA-2DEA-4E40-AB44-46CE32A5E468}"<br />

'<br />

If IsPostBack Then ' Use this to run ONLY ONCE when loaded<br />

' LoadTheDataGrid(AGUIDInStringFormat)<br />

Else ' Use this to reload every time<br />

LoadTheDataGrid(AGUIDInStringFormat)<br />

End If<br />

'<br />

End Sub<br />

Private Sub LoadTheDataGrid(ByVal OurStringGUID As String)<br />

'<br />

Dim SQLConn As New SqlConnection<br />

Dim SQLDataAdapter As New SqlDataAdapter<br />

Dim SQLSelectString As String<br />

Dim SQLSelectListHeaderString As String<br />

Dim SQLSelectListDetailString As String<br />

Dim DiscussionData As DataSet<br />

Dim TotalItems As Integer<br />

'<br />

' Open the database using a SQL Login:<br />

'<br />

SQLConn.ConnectionString = "Integrated Security=SSPI;Persist Security<br />

Info=False;Initial Catalog=Contoso1;Data Source=s2003e;"<br />

SQLConn.Open()<br />

'

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

Saved successfully!

Ooh no, something went wrong!