Solved

ado.Net - vb.net customised page using ASPEnterpriseManager.dll

Posted on 2009-07-16
6
180 Views
Last Modified: 2012-06-21
I am writting customised vb.net web-based pages and making use of ASPEnterpriseManager.dll The page references the dll to make the server connection. It lists all sql databse names with the following code.
For X = 0 To Server.Databases.Count - 1
Response.Write(Server.Databases(X))
Next
The question is that I want to list the db names in a repeater by adding the following.
If Items.Count <> 0 Then
Repeater1.DataSource = Server.Databases
Repeater1.DataBind()
It is not listing because I am not sure the following is correct in aspx page.
<%#Container.DataItem.ObjectName%>
The repeater is declared as follows:
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater
I have a copy of the source code for the dll, if needed to be posted to help.
Thanks in advance.
'****************************************************

'app/cmsDataMenu.aspx.vb

'****************************************************

Imports System

Imports System.Collections

Imports System.Configuration

Imports System.Data

Imports System.Linq

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.HtmlControls

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Xml.Linq

Imports System.Data.SqlClient

Imports System.IO

Imports System.Text

Imports System.Drawing

Imports System.Data.OleDb

Imports Microsoft.VisualBasic

Imports ASPEnterpriseManager
 

Namespace ASPEnterpriseManager.Pages

    

    Public Class cmsDataMenu

        Inherits System.Web.UI.Page

        Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList

        Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

        ' initiate variables etc

        Public Source As DataView

        Public Ds As DataSet

        Sub Page_Load(ByVal Sender As System.Object, ByVal E As System.EventArgs)

            Dim _Context As HttpContext = HttpContext.Current

            If Not Page.IsPostBack Then

                Dim X As Integer

                Dim Y As Integer

                Dim Server As ASPEnterpriseManager.Server = New ASPEnterpriseManager.Server

                Dim Database As ASPEnterpriseManager.Database

                'Dim Roles As ASPEnterpriseManager.ServerRoles = New ASPEnterpriseManager.ServerRoles

                'Roles.Load()

                Server.LoadDatabases()

                'If ConnectionString.InitialCatalog <> "" Then

                Database = New ASPEnterpriseManager.Database

                Database.LoadObjects()

                Session("Database") = Database

                'End If

                Session("Server") = Server

                Dim messageLabel As String = "ConnectionString.InitialCatalog"

                Y = 0

                For X = 0 To Server.Databases.Count - 1

                    Y = Y + 1

                    Response.Write(Server.Databases(X))

                Next

                If Items.Count <> 0 Then

                    Repeater1.DataSource = Server.Databases

                    Repeater1.DataBind()

                End If

            End If

        End Sub

        Private Shared Shadows Sub Init()

            ' initiate variables etc

        End Sub

        Protected Sub testDatabase_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
 

        End Sub

    End Class

    

End Namespace

'****************************************************

'app/cmsDataMenu.aspx

'****************************************************

<%@ Page Language="VB" src="cmsDataMenu.aspx.vb" Inherits="ASPEnterpriseManager.Pages.cmsDataMenu" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">

<title>Sever Connection</title>

<style type="text/css">

</style>

</head>

<!--

Start Code Section

-->

<body style="background-image: url(images/WebFront.jpg); background-repeat:repeat-x">

<form id ="form1" runat="server">

<% if request("Sync") <> "true" then AppInterface.SyncLeftFrame() 

    'if ConnectionString.InitialCatalog <> "" then %>

<table id="table2" style="z-index:102; position:absolute; top:10px; left:10px; width:auto">

<tr>

<td>

<div style='width:550px; height:550px; overflow:auto; background: #ffffff; border: 1px solid #000000;'>

<h6>Heading:2:</h6>

<asp:Repeater id="Repeater1" runat="server">

      <HeaderTemplate>

          <table width="100%" cellpadding="2" cellspacing="0">

	          	<tr><td class="TableHeader">	          

						<h6>cmsDataMenu</h6>

					</td><td class="TableHeader">

						<h6>Description</h6>

					</td></tr>

      </HeaderTemplate>

      <ItemTemplate>

	          <tr ><td  class="TableGrid">

	          <%#Container.DataItem.ObjectName%>

	          </td><td  class="TableGrid">

	          

	          </td></tr>

      </ItemTemplate>

      <FooterTemplate>

          </table>

      </FooterTemplate>

	</asp:Repeater>

</div>

</td>

</tr>

</table>

<!--

End Code Section

-->

</form>

</body>

</html>

Open in new window

0
Comment
Question by:homeshopper
  • 5
6 Comments
 
LVL 15

Accepted Solution

by:
jinal earned 500 total points
ID: 24870661
It would be nice that first take one Gridview control and bind Server.DataBases to GridView so it list down each column .
Then use that column name in Repeater control
0
 

Author Comment

by:homeshopper
ID: 24871019
Would it be possible to give an example using GridView?
I tried the following, but still not displaying database names.
DropDownList works in another page, but as you say,
it would be better to use GridView.
<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="true">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>
</asp:GridView>

 For X = 0 To Server.Databases.Count - 1
                    Response.Write(Server.Databases(X))
                    Y = Y + 1
                Next
                If Y <> 0 Then
                    GridView1.DataSource = Server.Databases
                    GridView1.DataBind()
                End If
The above gives the following error:
A field or property with the name 'Name' was not found on the selected data source. Line 57:                     GridView1.DataBind()
0
 

Author Comment

by:homeshopper
ID: 24871089
I have deleted <asp:BoundField DataField="Name" HeaderText="Name" />
it know works.
Just one more question, now it lists the db names, how can I
select an individual name and redirect to another gridview to display the tables contained in the selected database.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:homeshopper
ID: 24871231
I have the following code to try and display tables etc.
<%@ Page Language="VB" src="cmsData.aspx.vb" Inherits="ASPEnterpriseManager.Pages.cmsData" %>
<%@ Import Namespace="ASPEnterpriseManager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Sever Connection</title>
<style type="text/css">
</style>
</head>
<!--
Start Code Section
-->
<body style="background-image: url(images/WebFront.jpg); background-repeat:repeat-x">
<form id ="form1" runat="server">
<% if request("Sync") <> "true" then AppInterface.SyncLeftFrame()
    'if ConnectionString.InitialCatalog <> "" then %>
<table id="table2" style="z-index:102; position:absolute; top:10px; left:20px; width:auto">
<tr>
<td>
<div style='width:550px; height:140px; overflow:auto; background: #ffffff; border: 1px solid #000000;'>
<h6>Heading:2:</h6>
<% if request("Sync") <> "true" then AppInterface.SyncLeftFrame()
    'if ConnectionString.InitialCatalog <> "" then %>
                        <!--      
                        -->
                        <table>
                        <tr>
                        <td>
                         <img src="images/smallIcon_Database.gif" alt="" />
                         </td>
                         <td>
                         <h6>#<%= ConnectionString.InitialCatalog %>#</h6>
                         </td>
                         <td>
                        <a href="cmsData.aspx">&nbsp;Tables&nbsp;</a>
                        <a href="cmsViews.aspx">&nbsp;Views&nbsp;</a>
                        <a href="cmsStoredProcedures.aspx">&nbsp;Stored&nbsp;Procedures&nbsp;</a>
                        <a href="cmsUsers.aspx">&nbsp;Users&nbsp;</a>
                        <a href="cmsDatabaseRoles.aspx">&nbsp;DbRoles&nbsp;</a>
                        <!--
                        -->            
                <% 'Else%>
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;
                <% 'End If%>
                </td>
                </tr>
                </table>
</div>
</td>
</tr>
</table>
<table id="table3" style="z-index:103; position:absolute; top:160px; left:250px; width:auto">
<tr>
<td>
<div style='width:530px; height:350px; overflow:auto; background: #ffffff; border: 1px solid #000000;'>
<h6>Heading:3:</h6>
<asp:GridView id="GridView2" runat="server" AutoGenerateColumns="true">
<Columns>

</Columns>
</asp:GridView>
</div>
</td>
</tr>
</table>
<!--
End Code Section
-->
</form>
</body>
</html>
Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.Drawing
Imports System.Data.OleDb
Imports ASPEnterpriseManager

Namespace ASPEnterpriseManager.Pages

    Public Class cmsData
        Inherits System.Web.UI.Page
        Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
        Protected WithEvents GridView2 As System.Web.UI.WebControls.GridView
        ' initiate variables etc
        Public Source As DataView
        Public Ds As DataSet
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' set tabel & database selectedIndexChange
            testDatabase_SelectedIndexChanged(DropDownList1, Nothing)
            If Not IsPostBack Then
                'Response.Write(":Selected:")
            End If
            Init()
        End Sub
        Private Shared Shadows Sub Init()
            ' initiate variables etc
        End Sub
        Protected Sub testDatabase_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            GridView2.DataSource = Session("Database").Tables
            GridView2.DataBind()
        End Sub

    End Class

End Namespace      
0
 

Author Comment

by:homeshopper
ID: 24871296
Should be as follows:
If Not IsPostBack Then
                'Response.Write(":Selected:")
GridView2.DataSource = Session("Database").Tables
            GridView2.DataBind()
End If
I can display system tables, but I would like to display only the
tables applicable to the selected database
0
 

Author Comment

by:homeshopper
ID: 24871672
In the first gridview I have added a select button:
<h6>Heading:2:</h6>
<asp:GridView id="GridView1" runat="server" Font-Size="XX-Small" AutoGenerateColumns="true">
<Columns>
<asp:ButtonField CommandName="Select" Text="Select"  />
</Columns>
</asp:GridView>
I want it to display selected db name in <h6>#<%= ConnectionString.InitialCatalog %>#</h6>
This is in code under heading:3:
I have 3 pages in total displaying in an iFrame for the default.aspx
I suspect that system tables and not selected tables in heading:4;
are displayed because the db name is not displayed in heading:3;
I hope the above is clear enough to understand me.
Thanks in advance.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now