Click to See Complete Forum and Search --> : Web Part Custom Control Bug


pki15
July 8th, 2003, 03:04 PM
I'm trying to design a web part for Sharpoint server. A web part is basically an ASP.NET custom control. I thought this would be the appropriate place to post about the bug I have. The only way I can test my control is by putting it onto the Sharepoint Portal Server, and so the debugging is very hard to do, but all I know is my code has some bug in it that Sharepoint doesn't like. I'm basically trying to import an Access Database, and display it on Sharepoint.


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
Imports System.Data.OleDb

<DefaultProperty("Text"), ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"), XmlRoot(Namespace:="TestWebPart")> _
Public Class MyWebPart
Inherits WebPart
Dim dg As DataGrid
Protected Overrides Sub CreateChildControls()
dg = New DataGrid
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\users.mdb")
conn.Open()
Dim adapter As New OleDbDataAdapter("SELECT * FROM Users", conn)
Dim ds As New DataSet
adapter.Fill(ds)
dg.DataSource = ds
Controls.Add(dg)
End Sub
Protected Overrides Sub RenderWebPart(ByVal Output As HtmlTextWriter)
EnsureChildControls()
dg.RenderControl(Output)
End Sub
End Class

users.mdb is my database, and Users is the table inside it that I want to display. Does anyone see a bug in my code? I was also thinking that maybe there might be a problem with the link, since I'm compiling on my pc, which has the database on it, and then uploading to the sharepoint server. Any suggestions?