Help with Simple Web Form and Data access

rhm54

Member
Joined
Apr 9, 2007
Messages
22
Programming Experience
Beginner
Greetings,

I am very green to VB.NET and programming in general so please take it easy on me! I am trying to create a webform for my place of business that will provide an On-Call website for all the applications we support, that can be easily updated when the on call person changes.

The database is an access Database and it has two tables.

MainPhoneList - contains all the possible people that can be on call
Fields
Name - Full Name
Pager- Pager Number
Cell- Cell Number
Office - Office Number

OnCall- contains the current on call people.
Fields
Name - Full Name
Pager - Pager Number
Cell - Cell Number
Office - Office Number
Comment - Comments
Application - Application person is on call for

I have made a contact class that I will use for this program and coded it below

VB.NET:
Option Strict On
Public Class Contacts
    Private mstrName As String
    Private mstrCellNumber As String
    Private mstrDeskNumber As String
    Private mstrPagerNumber As String
    Private mstrComment As String
    Private Const g_strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & _
    "Data Source=C:\Documents and Settings\robby\Desktop\On-Call.mdb"

    Public Sub New()
        mstrName = ""
        mstrCellNumber = ""
        mstrDeskNumber = ""
        mstrPagerNumber = ""
        mstrComment = ""
    End Sub

    Public Sub New(ByVal strName As String, ByVal strCellNumber As String, ByVal strDeskNumber As String, _
    ByVal strPagerNumber As String, ByVal strComment As String)
        mstrName = strName
        mstrCellNumber = strCellNumber
        mstrDeskNumber = strDeskNumber
        mstrPagerNumber = strPagerNumber
        mstrComment = strComment
    End Sub

    Public Property Name() As String
        Get
            Return mstrName
        End Get
        Set(ByVal strName As String)
            mstrName = strName
        End Set
    End Property

    Public Property CellNumber() As String
        Get
            Return mstrCellNumber
        End Get
        Set(ByVal strCellNumber As String)
            mstrCellNumber = strCellNumber
        End Set
    End Property

    Public Property DeskNumber() As String
        Get
            Return mstrDeskNumber
        End Get
        Set(ByVal strDeskNumber As String)
            mstrDeskNumber = strDeskNumber
        End Set
    End Property

    Public Property PagerNumber() As String
        Get
            Return mstrPagerNumber
        End Get
        Set(ByVal strPagerNumber As String)
            mstrPagerNumber = strPagerNumber
        End Set
    End Property

    Public Property Comment() As String
        Get
            Return mstrComment
        End Get
        Set(ByVal strComment As String)
            mstrComment = strComment
        End Set
    End Property

    Public ReadOnly Property ConnectionString() As String
        Get
            Return g_strConnectionString
        End Get
    End Property
End Class
Now for the part that I don't know how to accomplish. The web form will use a combo box for the name field and populate it with the names from the mainphonelist table. When someone selects a name from the list it autopopulates the pager, cell, office, and comments boxes on the webform and updates the oncall database as well.

All help is appreciated!!!!
 
Alright I think I may be on the right track but I need some help with the datagrid web control. First thing I can't figure out how to add columns to it and secondly I see there is a place for datasource but when I pull the combo box down it is empty. In addition the Data menu only has two options and both are grayed out. Can someone point me in the right direction for using the datagrid control and adding a datasource.
 
Alright I think I may be on the right track but I need some help with the datagrid web control. First thing I can't figure out how to add columns to it and secondly I see there is a place for datasource but when I pull the combo box down it is empty. In addition the Data menu only has two options and both are grayed out. Can someone point me in the right direction for using the datagrid control and adding a datasource.
You need to add a datasource. You can add the datagrid (hopefully you are using the gridview if you are indeed using VS 2005 as your profile currently states) then click on the smartTag arrow that appears as you hover over the gridview. In the dialog that appears, click on the dropdown beside "Choose Data Source" and select "<New Data Source...>". The Data Source Configuration Wizard will walk you through creating the data source, and once you're finished the columns should be automatically added to the gridview. You can also use a custom data class as you've shown by selecting the objectDataSource in the Data Source Configuration Wizard.

I don't think you should need two tables here; just use a table with the fields you show in the second table (you called it OnCAll) plus a boolean field that shows if the person is on call or not. This way when a person goes on or off duty they can just change the value of the boolean field to reflect their on call status (and optionally change the Comment and Application fields).

http://asp.net has some good starter videos for data access. Click on the learn button at the top.
 
Thanks for the Help!!!!

Got another question. Is it possible to have a combo box in the Datagrid that when you click the edit button pulls in all the data from the mainphonelist table name field and when the user selects the name the on call table is updated with the information from the main phonelist.
 
Alright I am really close to having this down now. I actually scrapped the custom class idea and went with ASP.net completely and I have the form to where it will display everything that I want it to display but when I edit the page it does not update the page any ideas?

VB.NET:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
            DataKeyNames="Application" DataSourceID="OnCall" Style="z-index: 100; left: 13px;
            position: absolute; top: 66px">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="Application" HeaderText="Application" ReadOnly="True"
                    SortExpression="Application" />
                <asp:TemplateField HeaderText="Name" SortExpression="Name">
                    <EditItemTemplate>
                         <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="MainPhoneList"
                            DataTextField="Name" DataValueField="Name"
                            SelectedValue='<%# Bind("Name") %>' Style="position: static">
                        </asp:DropDownList><asp:AccessDataSource ID="MainPhoneList" runat="server" DataFile="~/App_Data/On-Call.mdb"
                            SelectCommand="SELECT * FROM [Main Phone List] ORDER BY [Name]"></asp:AccessDataSource>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Cell" HeaderText="Cell" SortExpression="Cell" />
                <asp:BoundField DataField="Desk" HeaderText="Desk" SortExpression="Desk" />
                <asp:BoundField DataField="Pager" HeaderText="Pager" SortExpression="Pager" />
                <asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="OnCall" runat="server" ConflictDetection="CompareAllValues"
            ConnectionString="<%$ ConnectionStrings:OnCallTable %>" DeleteCommand="DELETE FROM [Oncall] WHERE [Application] = ? AND [Name] = ? AND [Cell] = ? AND [Desk] = ? AND [Pager] = ? AND [Comment] = ?"
            InsertCommand="INSERT INTO [Oncall] ([Application], [Name], [Cell], [Desk], [Pager], [Comment]) VALUES (?, ?, ?, ?, ?, ?)"
            OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:OnCallTable.ProviderName %>"
            SelectCommand="SELECT * FROM [Oncall] ORDER BY [Application]" UpdateCommand="UPDATE [Oncall] SET [Name] = ?, [Cell] = ?, [Desk] = ?, [Pager] = ?, [Comment] = ? WHERE [Application] = ? AND [Name] = ? AND [Cell] = ? AND [Desk] = ? AND [Pager] = ? AND [Comment] = ?">
            <DeleteParameters>
                <asp:Parameter Name="original_Application" Type="String" />
                <asp:Parameter Name="original_Name" Type="String" />
                <asp:Parameter Name="original_Cell" Type="String" />
                <asp:Parameter Name="original_Desk" Type="String" />
                <asp:Parameter Name="original_Pager" Type="String" />
                <asp:Parameter Name="original_Comment" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Cell" Type="String" />
                <asp:Parameter Name="Desk" Type="String" />
                <asp:Parameter Name="Pager" Type="String" />
                <asp:Parameter Name="Comment" Type="String" />
                <asp:Parameter Name="original_Application" Type="String" />
                <asp:Parameter Name="original_Name" Type="String" />
                <asp:Parameter Name="original_Cell" Type="String" />
                <asp:Parameter Name="original_Desk" Type="String" />
                <asp:Parameter Name="original_Pager" Type="String" />
                <asp:Parameter Name="original_Comment" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Application" Type="String" />
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Cell" Type="String" />
                <asp:Parameter Name="Desk" Type="String" />
                <asp:Parameter Name="Pager" Type="String" />
                <asp:Parameter Name="Comment" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
         
    
    </div>
    </form>
</body>
</html>
 
Alright I have almost got this application finished but I am totally stuck and have been stuck for the last several days so I think that I now need some more help. To review this is what I have. I have two tables one named oncall and one named mainphonelist. The oncall table displays the information in a datagrid view and consists of the following fields:

Application - Primary Key
Name
Cell
Pager
Office
Comment

The MainPhonelist is the pool of all possible people who can be on call and it contains the following fields:

Name
Cell
Pager
Office

What I have done so far is create the gridview that shows all the data in the oncall table. When edit is clicked a dropdownlist is presented to the user containing all possible people from the mainphonelist.

Now here is the issue. I want the cell, pager, and office fields to update when the user selects a name from the drop down list with the corresponding information for that name. So for example, If I select John Doe from the list I would like to populate the cell, pager, and office fields with John Doe's information from the mainphonelist.

I know the program code needs to go into the DropDownList1_SelectedIndexChanged sub but I don't know what code I would use. I have tried the gridview1.selectedrows.cells(2).text object but I can't update it because it is readonly.

All Help is appreciated.
 
You have duplicate fields in the tables; that goes against good database design. Good database design eliminates duplicate data.
Did you have a problem with my proposed solution to have only one table including a boolean field to say whether the person is on call or not?
 
The only Problem is that a single person can be on call for multiple applications. I don't know how to accomplish this using only one table. Another issue is to be honest I don't even know the correct syntax to update the boolean value using ASP.net. If this was VB.NET it would be no problem but ASP.NET isn't as intuitive.
 
If this was VB.NET it would be no problem but ASP.NET isn't as intuitive.
Your code above is VB.NET. I believe you're confused about the definition of ASP.NET.
ASP.NET is a web application framework. VB.NET is one of the many languages that can be used in that application framework. ADO.NET is handled very much the same in winforms and webforms, the main difference comes with the variation in the databound controls.

The only Problem is that a single person can be on call for multiple applications.
I didn't realize that part. In that case you'll want to utilize a ForeignKey, a technique used to avoid duplicate data. The foreign key identifies a column or a set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. The columns in the referenced table must form a primary key or unique key. In other words, you only need to add the PrimaryKey from the main table to the secondary table and use the power of SQL and the Join function to combine the two.

http://asp.net has some very good video tutorials as well as quick starts. Click the learn menu item at the top.
 
I didn't realize that part. In that case you'll want to utilize a ForeignKey, a technique used to avoid duplicate data. The foreign key identifies a column or a set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. The columns in the referenced table must form a primary key or unique key. In other words, you only need to add the PrimaryKey from the main table to the secondary table and use the power of SQL and the Join function to combine the two.

My project has morphed many times since I started it and in its current state I believe it is mostly asp.net. I feel real dumb but I don't quite understand what you mean by the foreign key. I uploaded my very small project into a zip file and put it here

http://rapidshare.com/files/31874554/WebSite3.zip

If you have time could you look at it and see what I am doing wrong? Honestly this is my first attempt at creating a useful application of any type and I have only taken a class in VB.NET. All I Know about ASP.NET I learned from the videos you provided from Http://asp.net. I really just feel super close but I can't make the leap to the other side.
 
After looking at your project, I can't really tell what you're trying to do.
If you would describe the functionality you're after I could possibly come up with something.
 
Last edited:
After looking at your project, I can't really tell what you're trying to do.
If you would describe the functionality your after I could possibly come up with something.

Basically what I am doing is making a site that serves as an OnCall website for the large number of applications we support. When viewing the website it should display the application, Person on call's name, desk number, cell number, pager number, and comment. When editing a dropdown list of all available names should be presented and once a selection is made the phone numbers should update to the person selected as well.

I think I have overcome my major hurdle and have gotten the site to a point that when I edit it I can update the phone numbers but I still have a few minor issues.

The site as it stands now is here

http://rapidshare.com/files/32824954/WebSite4.zip

1. Is there a way to make the gridview update its view of the cell phone, desk phone and pager number fields once a selection is made in the dropdownlist but not post to the database until update is clicked?

2. Is there a way to add a tooltip to the edit, update, and cancel images so that when the user hovers over the image for Edit they are presented with a tooltip that states "Edit"

3. How can I merge the security for this site into our exsisting LDAP security?
 
Back
Top