Re: Web part is empty (code taken directly out of book)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Patrick Tisseghem (patrick_at_u2u.be)
Date: 10/22/04


Date: Fri, 22 Oct 2004 08:13:46 +0200

this.EnsureChildControls as the first line in your renderwebpart methods?

-- 
Regards,
Patrick Tisseghem
http://blog.u2u.info/DottextWeb/patrick/
"Tom Brophy" <TomBrophy@discussions.microsoft.com> wrote in message
news:4E32D4CC-29B7-4DF8-A59C-B8A4B6DEE440@microsoft.com...
> I am using the Microsoft SharePoint Building Office 2003 Solutions book
and
> am using their sample of showing a table of authors from the PubsAuthors
> sample database (beginning on p 178).  I am just changing the code to
display
> all the sites that are on our SharePoint site (using webs table instead of
> sites table because the sites table only shows the top level sites - I
want
> to show parents and children and personal sites.
>
> Here is the code - almost directly taken from the book except for the
> changes for the different database/table.
>
> I am not able to test directly on the machine that has VB.net (doesn't
have
> sharepoint).  When I build the project and create the cab and install it
on
> the server - I am able to install the web part but it is blank - doesn't
show
> table and doesn't show error message.  I had also tried creating a web
part
> that just shows the date but that was always blank as well - thought it
was
> something that I just wasn't understanding (I am new to creating web
parts).
> Does anybody know what the problem might be?
>
> Thanks in advance for any help.
>
> Tom
>
>
> Heres the code for the Site.VB:
>
>
> Imports System
> Imports System.ComponentModel
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
> Imports System.Xml.Serialization
> Imports Microsoft.SharePoint
> Imports Microsoft.SharePoint.Utilities
> Imports Microsoft.SharePoint.WebPartPages
>
> 'Description for WebPart1.
> <DefaultProperty(""), ToolboxData("<{0}:View runat=server></{0}:View>"),
> XmlRoot(Namespace:="THSite")> _
> Public Class View
>     Inherits Microsoft.SharePoint.WebPartPages.WebPart
>
>     Private strSQLserver As String = ""
>     Private strDatabase As String = ""
>     Private strUserName As String = ""
>     Private strPassword As String = ""
>
>     'SQL server name
>     <Browsable(True), Category("Miscellaneous"), DefaultValue(""),
> WebPartStorage(Storage.Shared), FriendlyName("SQLServer"),
Description("The
> server with SQL table")> _
>     Property SQLServer() As String
>         Get
>             Return strSQLserver
>         End Get
>
>         Set(ByVal Value As String)
>             strSQLserver = Value
>         End Set
>     End Property
>
>     'Database name
>     <Browsable(True), Category("Miscellaneous"), DefaultValue(""),
> WebPartStorage(Storage.Shared), FriendlyName("Database"), Description("The
> database with SQL info")> _
>     Property Database() As String
>         Get
>             Return strDatabase
>         End Get
>
>         Set(ByVal Value As String)
>             strDatabase = Value
>         End Set
>     End Property
>
>     'User name
>     <Browsable(True), Category("Miscellaneous"), DefaultValue(""),
> WebPartStorage(Storage.Shared), FriendlyName("UserName"), Description("The
> account to access the database")> _
>     Property UserName() As String
>         Get
>             Return strUserName
>         End Get
>
>         Set(ByVal Value As String)
>             strUserName = Value
>         End Set
>     End Property
>
>     'Password
>     <Browsable(True), Category("Miscellaneous"), DefaultValue(""),
> WebPartStorage(Storage.Shared), FriendlyName("Password"), Description("The
> password to access the database")> _
>     Property Password() As String
>         Get
>             Return strPassword
>         End Get
>
>         Set(ByVal Value As String)
>             strPassword = Value
>         End Set
>     End Property
>
>     'Render this Web Part to the output parameter specified.
>     Protected Overrides Sub RenderWebPart(ByVal output As
> System.Web.UI.HtmlTextWriter)
>         Dim objDataSet As System.Data.DataSet
>
>         'setup connection string from custom properties
>         Dim strConnection As String
>         strConnection += "Password=" & Password
>         strConnection += ";Persist Security Info=True;User ID="
>         strConnection += UserName + "Initial Catalog=" + Database
>         strConnection += ";Data Source=" + SQLServer
>
>         'strConnection = "Provider=SQLOLEDB.1;Password=123123;Persist
> Security Info=True;User ID=sa;Initial Catalog=THPortal1_SITE;Data
> Source=THPORTAL"
>
>         'query database
>         Dim strSQL As String = "SELECT * from Webs"
>
>         'try to run the query
>         Try
>             With New System.Data.SqlClient.SqlDataAdapter
>                 objDataSet = New DataSet("root")
>
>                 .SelectCommand = _
>                 New System.Data.SqlClient.SqlCommand(strSQL, _
>                 New System.Data.SqlClient.SqlConnection(strConnection))
>
>                 .Fill(objDataSet, "Webs")
>             End With
>         Catch ex As Exception
>             lblMessage.Text = ex.Message
>             Exit Sub
>         End Try
>
>         'bind to grid
>         Try
>             With grdNames
>                 .DataSource = objDataSet
>                 .DataMember = "webs"
>                 .DataBind()
>             End With
>         Catch ex As Exception
>             lblMessage.Text = ex.message
>             Exit Sub
>         End Try
>
>         'draw the controls in an html table
>         With output
>             .Write("<TABLE BORDER=0 WIDTH=100%>")
>             .Write("<TR>")
>             .Write("<TD>")
>             grdNames.RenderControl(output)
>             .Write("</TD>")
>             .Write("</TR>")
>             .Write("<TR>")
>             .Write("<TD>")
>             lblMessage.RenderControl(output)
>             .Write("</TD>")
>             .Write("</TR>")
>             .Write("</TABLE>")
>         End With
>
>     End Sub
>
>     Protected WithEvents grdNames As DataGrid
>     Protected WithEvents lblMessage As Label
>
>     Protected Overrides Sub CreateChildControls()
>         'Grid to display results
>         grdNames = New DataGrid
>         With grdNames
>             .Width = Unit.Percentage(100)
>             .HeaderStyle.Font.Name = "arial"
>             .HeaderStyle.Font.Size = New
FontUnit(FontSize.AsUnit).Point(10)
>             .HeaderStyle.Font.Bold = True
>             .HeaderStyle.ForeColor = System.Drawing.Color.Wheat
>             .HeaderStyle.BackColor = System.Drawing.Color.DarkBlue
>             .AlternatingItemStyle.BackColor =
System.Drawing.Color.LightCyan
>         End With
>         Controls.Add(grdNames)
>         'label for error messages
>         lblMessage = New Label
>         With lblMessage
>             .Width = Unit.Percentage(100)
>             .Font.Name = "arial"
>             .Font.Size = New FontUnit(FontSize.AsUnit).Point(10)
>             .Text = ""
>         End With
>         Controls.Add(lblMessage)
>     End Sub
> End Class
>


Relevant Pages

  • Web part is empty (code taken directly out of book)
    ... I am using the Microsoft SharePoint Building Office 2003 Solutions book and ... sample database. ... Imports System.ComponentModel ... Property SQLServerAs String ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: DoCmd.TransferText error with Schema.ini import specification
    ... spec. ... The database engine doesn't care. ... it for subsequent imports with the TransferText method. ... Function fncImportTextFile(strImportTbl As String, blnRow1FldNames As ...
    (microsoft.public.access.externaldata)
  • Re: A little Rolodex [revised]
    ... including alpha sort and searching for any embedded string, ... In this application, a database is a directory, ... you may optionally provide any alternate UCASE program, ... NN -> first store NN as key length ...
    (comp.sys.hp48)
  • Re: return multiple rows from sql statement
    ... strings from input values is almost certainly a safe path to SQL ... Also, being a MySQL function, it knows what MySQL needs or uses. ... All characters that are entered in the fields make their way into the database unaltered. ... The insert of what surprisinlgly was NOT a syntax error, but a string called "mysql_insert_id" into an integer field resulted in the value zero being put in. ...
    (comp.lang.php)
  • Re: Code to delete/unlink Linked tables
    ... Public intLinkODBCTables As Variant, intLinkDB2Tables As Variant ... Public strLinkBackendDB As String, strLinkDSNname As String, strLinkLibName ... ' MsgBox "This database is in MDE format...I will delete/recreate ODBC ... Public Sub fncLinkDB2Table() ...
    (microsoft.public.access.modulesdaovba)