I've been working on a page that has ddls populating other ddls and form fields. Right now I'm getting this error:

erver Error in '/HRIService' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 115: ' Try
Line 116: cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
Line 117: cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
Line 118:
Line 119: conn.Open()


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx.vb Line: 117

Here is my code:

Imports System.Data
Imports System.Data.SqlClient

Partial Class AddCall
    Inherits System.Web.UI.Page

    Dim conn As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
    Dim cmd As System.Data.SqlClient.SqlCommand
    Dim reader As System.Data.SqlClient.SqlDataReader
    Dim reader2 As System.Data.SqlClient.SqlDataReader

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

        If Not Page.IsPostBack Then

            Dim bol As Boolean = False
            Dim conID As String = Trim(Request.QueryString("conID")).ToString()
            Dim cusID As String = Trim(Request.QueryString("cusID")).ToString()

            If Len(cusID) > 0 And Len(conID) > 0 Then

                Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
                Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
                Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
                Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
                Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
                Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
                Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
                Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
                Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)

                ' Try
                cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
                cmd.Parameters.AddWithValue("@cusID", cusID)

                conn.Open()
                reader = cmd.ExecuteReader()

                If reader.HasRows Then
                    DropDownList2.DataSource = reader
                    DropDownList2.DataTextField = "ContactName"
                    DropDownList2.DataValueField = "cusID"
                    DropDownList2.DataBind()
                    DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
                    DropDownList2.SelectedIndex = DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(conID))
                Else
                    DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --"))
                End If

                reader.Close()

                cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
                cmd.Parameters.AddWithValue("@cusID", cusID)
                cmd.Parameters.AddWithValue("@ContactID", conID)
                reader2 = cmd.ExecuteReader()

                If reader.HasRows Then
                    While reader.Read()
                        Company.Text = reader.Item("Company").ToString
                        Address1.Text = reader.Item("Address1").ToString
                        Address2.Text = reader.Item("Address2").ToString
                        Phone.Text = reader.Item("Phone").ToString
                        FirstName.Text = reader.Item("FirstName").ToString()
                        LastName.Text = reader.Item("LastName").ToString()
                        City.Text = reader.Item("City").ToString()
                        State.Text = reader.Item("State").ToString()
                        Zip.Text = reader.Item("Zip").ToString()
                    End While
                End If

                reader.Close()
                conn.Close()
                '  Catch
                ' End Try

                bol = True

            End If

            cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, Company FROM Customers", conn)

            ' Try
            conn.Open()
            reader = cmd.ExecuteReader()

            If reader.HasRows Then
                DropDownList1.DataSource = reader
                DropDownList1.DataTextField = "Company"
                DropDownList1.DataValueField = "cusID"
                DropDownList1.DataBind()
                DropDownList1.Items.Insert(0, ("-- Choose a Company --"))
                If bol = True Then DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(conID))
            Else
                DropDownList1.Items.Insert(0, ("-- Error: No Companies Found --"))
            End If

            reader.Close()
            conn.Close()
            ' Catch
            ' End Try

        End If

    End Sub


    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

        Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
        Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
        Dim DropDownListEquip As DropDownList = TryCast(FormView1.FindControl("DropDownListEquip"), DropDownList)
        Dim DropDownList1 As DropDownList = TryCast(FormView1.FindControl("DropDownList1"), DropDownList)


        ' Try
        cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

        conn.Open()
        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            DropDownList2.DataSource = reader
            DropDownList2.DataTextField = "ContactName"
            DropDownList2.DataValueField = "cusID"
            DropDownList2.DataBind()
            DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
        Else
            DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --"))
        End If

        reader.Close()

        cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company + ' - ' + b.Description As CompanyEqpDesc, b.eqpID FROM Manufacturers a JOIN Equipment b ON a.mfgID=b.mfgID WHERE b.eqpID IN (SELECT eqpID FROM Cus_Equip WHERE cusID=@cusID)", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

        reader2 = cmd.ExecuteReader()

        If reader.HasRows Then
            DropDownListEquip.DataSource = reader
            DropDownListEquip.DataTextField = "CompanyEqpDesc"
            DropDownListEquip.DataValueField = "eqpID"
            DropDownListEquip.DataBind()
            DropDownListEquip.Items.Insert(0, ("-- Choose Equipment --"))
        Else
            DropDownListEquip.Items.Insert(0, ("-- Error: No Equipment Found --"))
        End If

        reader.Close()
        conn.Close()
        ' Catch
        '  End Try

        FirstName.Text = ""
        LastName.Text = ""

    End Sub


    Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged

        Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
        Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
        Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
        Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
        Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
        Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
        Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
        Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
        Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
        Dim DropDownList2 As DropDownList = TryCast(FormView1.FindControl("DropDownList2"), DropDownList)

        cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
        cmd.Parameters.AddWithValue("@conID", DropDownList2.SelectedValue)

        ' Try
        conn.Open()
        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            While reader.Read()
                Company.Text = reader.Item("Company").ToString
                Address1.Text = reader.Item("Address1").ToString
                Address2.Text = reader.Item("Address2").ToString
                Phone.Text = reader.Item("Phone").ToString
                FirstName.Text = reader.Item("FirstName").ToString()
                LastName.Text = reader.Item("LastName").ToString()
                City.Text = reader.Item("City").ToString()
                State.Text = reader.Item("State").ToString()
                Zip.Text = reader.Item("Zip").ToString()
            End While
        End If

        reader.Close()
        conn.Close()
        ' Catch
        'End Try

    End Sub


    Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim disID As String
        Dim recs As Integer = 0
        Dim Problem As TextBox = TryCast(FormView1.FindControl("Problem"), TextBox)
        Dim DropDownListPriority As DropDownList = TryCast(FormView1.FindControl("DropDownListPriority"), DropDownList)
        Dim DropDownListBill As DropDownList = TryCast(FormView1.FindControl("DropDownListBill"), DropDownList)
        Dim Notes As TextBox = TryCast(FormView1.FindControl("Notes"), TextBox)

        cmd = New System.Data.SqlClient.SqlCommand("INSERT INTO Dispatch (cusID, Problem, Priority, Contract) VALUES (@cusID, @Problem, @Priority, @Contract); SELECT SCOPE_IDENTITY()", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedItem.Value)
        cmd.Parameters.AddWithValue("@Problem", Trim(Problem.Text))
        cmd.Parameters.AddWithValue("@Priority", DropDownListPriority.SelectedItem.Text)
        cmd.Parameters.AddWithValue("@Contract", DropDownListBill.SelectedItem.Text)

        '   Try
        conn.Open()
        disID = cmd.ExecuteScalar()

        cmd = New System.Data.SqlClient.SqlCommand("INSERT INTO DispatchEvents (disID, Notes) VALUES (@disID, @Notes)", conn)
        cmd.Parameters.AddWithValue("@disID", disID)
        cmd.Parameters.AddWithValue("@Notes", Trim(Notes.Text))

        recs = cmd.ExecuteNonQuery()
        conn.Close()

        If Len(disID) > 0 Then recs += 1

        If recs > 1 Then
            Response.Redirect("Dispatch.aspx")
        Else
            Response.Write("Recs Counted: " & recs & " out of 2.")
        End If
        ' Catch ex As System.Data.SqlClient.SqlException
        ' Response.Write(ex)
        ' End Try

    End Sub

End Class

Hi foundsheep, i got your message. Make sure that your dropdown's enableViewState attribute is set to true and make sure that you fill the drop down between the "not IsPostBack" block.

Modify your page_load handler like this :

protected void Page_Load(object sender, EventArgs e)
{
    if(!IstPostBack)
    {
        fill the dropdowns();
    }
}

yeah, I did his coding but I am inline, so there's some flaws here.

It's within the ispostback.

Is that C#? What would it look like in VB?

It's already on there. VB.NET version of his code:

C#:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
fill the dropdowns();
}
}

VB.NET:
protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
if Not Page.IsPostBack then
  'fill the dropdowns();
end if

So, that wasn't the solution.

You said it is within ispostback, it must be within "not ispostback"

I meant it's within a postback statement. So yes it's within this:

If Not Page.IsPostBack Then
...
End If

I had some tell me this. Is it a valid question?

In this line here
Code:

cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

Check and make sure that DropDownList1.SelectedValue is not null

No, it's not a valid question. The reason is because this is on an event that isn't triggered until it is selected. Therefore, if you are getting this error at runtime and cannot even load the page, then that is not it. That event hasn't been triggered. So there is an error somewhere.

Post your aspx code please so I can do one more DEBUG for you.

here you go:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AddCall.aspx.vb" Inherits="AddCall" title="Hackworth Reprographics Service Express - Add Call" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style5
        {
            font-family: Verdana;
            font-size: 12px;
            color: #000000;
            text-align: left;
            font-weight: bold;
        }
        .style6 { height: 20px; }
        .style7 { }
        .style8 { }
        .style9 { width: 26px; }
        .style10 { width: 79px; }
        .style11 { width: 134px; }
        .style12 { width: 50px; }
        .style13 { width: 40px; }
        .style14 { width: 149px; }
        .style15 { width: 86px; }
        .style16
        {
            width: 86px;
            height: 22px;
        }
        .style17
        {
            width: 149px;
            height: 22px;
        }
        .style18
        {
            width: 40px;
            height: 22px;
        }
        .style19
        {
            width: 50px;
            height: 22px;
        }
        .style20
        {
            width: 26px;
            height: 22px;
        }
        .style21
        {
            width: 134px;
            height: 22px;
        }
        .style22
        {
            width: 79px;
            height: 22px;
        }
        .style23 { height: 22px; }
    </style>
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table width="100%" cellpadding="0" cellspacing="0" class="topblack">
            <tr>
                <td width="177px" class="rightborder" bgcolor="#CCCCCC" valign="top">
                    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" 
                        ImageSet="Arrows" style="text-align: left">
                        <ParentNodeStyle Font-Bold="False" />
                        <HoverNodeStyle Font-Underline="True" ForeColor="Maroon" />
                        <SelectedNodeStyle Font-Underline="True" ForeColor="Maroon" 
                            HorizontalPadding="0px" VerticalPadding="0px" />
                        <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" 
                            HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
                    </asp:TreeView>
                    <br />
                </td>
                <td valign="top">
                   
                    <table cellspacing="2" cellpadding="0" width="100%">
                        <tr>
                            <td>
                                <div align="left"><asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" | ">
                                    <CurrentNodeStyle CssClass="header" Font-Underline="False" ForeColor="Black" />
                                    <NodeStyle CssClass="header" ForeColor="#990000" />
                                    <RootNodeStyle CssClass="header" ForeColor="Maroon" />
                                </asp:SiteMapPath></div>
                            </td>
                            <td>
                                <div align="right">    <asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="maintext" />
                            </div></td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align: left">
                                <table align="center" cellpadding="0" class="style2" style="width: 99%">
                                    <tr>
                                        <td>
                                            <table cellpadding="0" class="style2">
                                                <tr>
                                                    <td>
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <span class="style5">Select a Company:</span>
                                                        <asp:DropDownList 
                                                            ID="DropDownList1" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            ForeColor="Maroon"
                                                            AutoPostBack="True" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td
                                                        <span class="maintext"><b>Select a Contact:</b> &nbsp;</span>&nbsp;
                                                        <asp:DropDownList 
                                                            ID="DropDownList2" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            ForeColor="Maroon"
                                                            AutoPostBack="True" />
                                                        <asp:Label ID="labelSelection" 
                                                            runat="server" style="z-index: 102; left: 368px; position: absolute; top: 144px">
                                                        </asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style6">
                                                        <asp:HyperLink 
                                                            ID="AddCompany" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            Font-Bold="True" 
                                                            ForeColor="Maroon" 
                                                            NavigateUrl="~/ServiceExpress/DisAddCo.aspx">Add New Company?</asp:HyperLink>
                                                        <br />
                                                        <br />
                                                        <asp:FormView ID="FormView1" runat="server" DefaultMode="Insert" 
                                                            DataSourceID="SqlDataSource4">
                                                            <InsertItemTemplate>
                                                                <table cellpadding="0" class="style2">
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Company:</td>
                                                                        <td colspan="5" style="margin-left: 40px">
                                                                            <asp:TextBox ID="Company" runat="server" Width="250px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Phone:</td>
                                                                        <td>
                                                                            <asp:TextBox ID="Phone" runat="server" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            First Name:</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="FirstName" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Last Name:
                                                                        </td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="LastName" runat="server" style="margin-bottom: 0px" 
                                                                                Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Technician:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListTech" runat="server" CssClass="maintext" 
                                                                        DataSourceID="SqlDataSource3" DataTextField="techid" 
                                                                        DataValueField="UserID" AppendDataBoundItems="True">
                                                                        <asp:ListItem Value="">Unassigned</asp:ListItem>
                                                                         </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Address:</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="Address1" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Priority:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListPriority" runat="server" CssClass="maintext">
                                                                                <asp:ListItem Selected="True">Select One</asp:ListItem>
                                                                                <asp:ListItem>Red (High)</asp:ListItem>
                                                                                <asp:ListItem>Yellow</asp:ListItem>
                                                                                <asp:ListItem>Blue</asp:ListItem>
                                                                                <asp:ListItem>Green (Low)</asp:ListItem>
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style15">
                                                                            &nbsp;</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="Address2" runat="server" Width="200px" 
                                                                                style="margin-bottom: 0px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Billing:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListBill" runat="server" CssClass="maintext">
                                                                                <asp:ListItem Selected="True">Select One</asp:ListItem>
                                                                                <asp:ListItem>Contract</asp:ListItem>
                                                                                <asp:ListItem>Time/Materials</asp:ListItem>
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            City:</td>
                                                                        <td class="style14">
                                                                            <asp:TextBox ID="City" runat="server" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            State:</td>
                                                                        <td class="style12">
                                                                            <asp:TextBox ID="State" runat="server" Width="30px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Zip:</td>
                                                                        <td class="style11">
                                                                            <asp:TextBox ID="Zip" runat="server" Width="80px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style16">
                                                                            </td>
                                                                        <td class="style17">
                                                                            </td>
                                                                        <td class="style18">
                                                                            </td>
                                                                        <td class="style19">
                                                                            </td>
                                                                        <td class="style20">
                                                                            </td>
                                                                        <td class="style21">
                                                                            </td>
                                                                        <td class="style22">
                                                                            </td>
                                                                        <td class="style23">
                                                                            </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Equipment:</td>
                                                                        <td class="style14">
                                                                            <asp:DropDownList ID="DropDownListEquip" runat="server" CssClass="maintext" />
                                                                        </td>
                                                                        <td class="style13">
                                                                            &nbsp;</td>
                                                                        <td class="style12">
                                                                            &nbsp;</td>
                                                                        <td class="style9">
                                                                            &nbsp;</td>
                                                                        <td class="style11">
                                                                            &nbsp;</td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext" valign="top">
                                                                            Problem:</td>
                                                                        <td class="style8" colspan="5">
                                                                            <asp:TextBox ID="Problem" runat="server" Height="100px" TextMode="MultiLine" 
                                                                        Width="400px"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext" valign="top">
                                                                            Notes:</td>
                                                                        <td>
                                                                            <asp:TextBox ID="Notes" runat="server" Height="100px" TextMode="MultiLine" 
                                                                        Width="400px"></asp:TextBox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style7" colspan="8" valign="top">
                                                                            <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
                                                                            &nbsp;<asp:Button ID="Button2" runat="server" Text="Reset" />
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </InsertItemTemplate>
                                                        </asp:FormView>
                                                        <asp:SqlDataSource ID="SqlDataSource4" runat="server"></asp:SqlDataSource>
                                                        <br />
                                                        &nbsp;<br />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>

                                <asp:SqlDataSource 
                                    ID="SqlDataSource3" 
                                    runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:HRIServiceConnectionString1 %>"                                
                                    SelectCommand="SELECT [UserID], [FirstName]+ ' ' + [LastName] AS techid FROM [aspnet_Users] WHERE [isTech] = 'True' ORDER BY [LastName], [FirstName]">
                                </asp:SqlDataSource>
                            </td>
                        </tr>
                    </table>
                    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
                </td>
            </tr>
        </table>
</asp:Content>

Okay, save a backup of your current ASPX file, name it something like: backup.aspx

And then replace all your code in your current ASPX file with this and let me know what it says:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" title="Hackworth Reprographics Service Express - Add Call" %>
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.Data.SqlClient" %>

<script language="vb" runat="server">
    Dim conn As New SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
    Dim cmd As SqlCommand
    Dim reader As SqlDataReader
    Dim reader2 As SqlDataReader

    Public Sub Page_Load(ByVal S As Object, ByVal E As EventArgs)

        If Not Page.IsPostBack Then

            Dim bol As Boolean = False
            Dim conID As String = Trim(Request.QueryString("conID")).ToString()
            Dim cusID As String = Trim(Request.QueryString("cusID")).ToString()

            If Len(cusID) > 0 And Len(conID) > 0 Then

                ' Try
                cmd = New SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
                cmd.Parameters.AddWithValue("@cusID", cusID)

                conn.Open()
                reader = cmd.ExecuteReader()

                If reader.HasRows Then
                    DropDownList2.DataSource = reader
                    DropDownList2.DataTextField = "ContactName"
                    DropDownList2.DataValueField = "cusID"
                    DropDownList2.DataBind()
                    DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
                    DropDownList2.SelectedIndex = DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(conID))
                Else
                    DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --"))
                End If

                reader.Close()

                cmd = New SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
                cmd.Parameters.AddWithValue("@cusID", cusID)
                cmd.Parameters.AddWithValue("@ContactID", conID)
                reader2 = cmd.ExecuteReader()

                If reader.HasRows Then
                    While reader.Read()
                        Company.Text = reader("Company").ToString
                        Address1.Text = reader("Address1").ToString
                        Address2.Text = reader("Address2").ToString
                        Phone.Text = reader("Phone").ToString
                        FirstName.Text = reader("FirstName").ToString()
                        LastName.Text = reader("LastName").ToString()
                        City.Text = reader("City").ToString()
                        State.Text = reader("State").ToString()
                        Zip.Text = reader("Zip").ToString()
                    End While
                End If

                reader.Close()
                conn.Close()
                '  Catch
                ' End Try

                bol = True

            End If

            cmd = New SqlCommand("SELECT cusID, Company FROM Customers", conn)

            ' Try
            conn.Open()
            reader = cmd.ExecuteReader()

            If reader.HasRows Then
                DropDownList1.DataSource = reader
                DropDownList1.DataTextField = "Company"
                DropDownList1.DataValueField = "cusID"
                DropDownList1.DataBind()
                DropDownList1.Items.Insert(0, ("-- Choose a Company --"))
                If bol = True Then DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(conID))
            Else
                DropDownList1.Items.Insert(0, ("-- Error: No Companies Found --"))
            End If

            reader.Close()
            conn.Close()
            ' Catch
            ' End Try

        End If

    End Sub


    Public Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        ' Try
        cmd = New SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

        conn.Open()
        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            DropDownList2.DataSource = reader
            DropDownList2.DataTextField = "ContactName"
            DropDownList2.DataValueField = "cusID"
            DropDownList2.DataBind()
            DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
        Else
            DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --"))
        End If

        reader.Close()

        cmd = New SqlCommand("SELECT a.Company + ' - ' + b.Description As CompanyEqpDesc, b.eqpID FROM Manufacturers a JOIN Equipment b ON a.mfgID=b.mfgID WHERE b.eqpID IN (SELECT eqpID FROM Cus_Equip WHERE cusID=@cusID)", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

        reader2 = cmd.ExecuteReader()

        If reader.HasRows Then
            DropDownListEquip.DataSource = reader
            DropDownListEquip.DataTextField = "CompanyEqpDesc"
            DropDownListEquip.DataValueField = "eqpID"
            DropDownListEquip.DataBind()
            DropDownListEquip.Items.Insert(0, ("-- Choose Equipment --"))
        Else
            DropDownListEquip.Items.Insert(0, ("-- Error: No Equipment Found --"))
        End If

        reader.Close()
        conn.Close()
        ' Catch
        '  End Try

        FirstName.Text = ""
        LastName.Text = ""

    End Sub


    Public Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        cmd = New SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
        cmd.Parameters.AddWithValue("@conID", DropDownList2.SelectedValue)

        ' Try
        conn.Open()
        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            While reader.Read()
                Company.Text = reader("Company").ToString
                Address1.Text = reader("Address1").ToString
                Address2.Text = reader("Address2").ToString
                Phone.Text = reader("Phone").ToString
                FirstName.Text = reader("FirstName").ToString()
                LastName.Text = reader("LastName").ToString()
                City.Text = reader("City").ToString()
                State.Text = reader("State").ToString()
                Zip.Text = reader("Zip").ToString()
            End While
        End If

        reader.Close()
        conn.Close()
        ' Catch
        'End Try

    End Sub


    Public Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim disID As String
        Dim recs As Integer = 0

        cmd = New SqlCommand("INSERT INTO Dispatch (cusID, Problem, Priority, Contract) VALUES (@cusID, @Problem, @Priority, @Contract); SELECT SCOPE_IDENTITY()", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedItem.Value)
        cmd.Parameters.AddWithValue("@Problem", Trim(Problem.Text))
        cmd.Parameters.AddWithValue("@Priority", DropDownListPriority.SelectedItem.Text)
        cmd.Parameters.AddWithValue("@Contract", DropDownListBill.SelectedItem.Text)

        '   Try
        conn.Open()
        disID = cmd.ExecuteScalar()

        cmd = New SqlCommand("INSERT INTO DispatchEvents (disID, Notes) VALUES (@disID, @Notes)", conn)
        cmd.Parameters.AddWithValue("@disID", disID)
        cmd.Parameters.AddWithValue("@Notes", Trim(Notes.Text))

        recs = cmd.ExecuteNonQuery()
        conn.Close()

        If Len(disID) > 0 Then recs += 1

        If recs > 1 Then
            Response.Redirect("Dispatch.aspx")
        Else
            Response.Write("Recs Counted: " & recs & " out of 2.")
        End If
        ' Catch ex As SqlException
        ' Response.Write(ex)
        ' End Try

    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style5
        {
            font-family: Verdana;
            font-size: 12px;
            color: #000000;
            text-align: left;
            font-weight: bold;
        }
        .style6 { height: 20px; }
        .style7 { }
        .style8 { }
        .style9 { width: 26px; }
        .style10 { width: 79px; }
        .style11 { width: 134px; }
        .style12 { width: 50px; }
        .style13 { width: 40px; }
        .style14 { width: 149px; }
        .style15 { width: 86px; }
        .style16
        {
            width: 86px;
            height: 22px;
        }
        .style17
        {
            width: 149px;
            height: 22px;
        }
        .style18
        {
            width: 40px;
            height: 22px;
        }
        .style19
        {
            width: 50px;
            height: 22px;
        }
        .style20
        {
            width: 26px;
            height: 22px;
        }
        .style21
        {
            width: 134px;
            height: 22px;
        }
        .style22
        {
            width: 79px;
            height: 22px;
        }
        .style23 { height: 22px; }
    </style>
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table width="100%" cellpadding="0" cellspacing="0" class="topblack">
            <tr>
                <td width="177px" class="rightborder" bgcolor="#CCCCCC" valign="top">
                    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" 
                        ImageSet="Arrows" style="text-align: left">
                        <ParentNodeStyle Font-Bold="False" />
                        <HoverNodeStyle Font-Underline="True" ForeColor="Maroon" />
                        <SelectedNodeStyle Font-Underline="True" ForeColor="Maroon" 
                            HorizontalPadding="0px" VerticalPadding="0px" />
                        <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" 
                            HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
                    </asp:TreeView>
                    <br />
                </td>
                <td valign="top">
                   
                    <table cellspacing="2" cellpadding="0" width="100%">
                        <tr>
                            <td>
                                <div align="left"><asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" | ">
                                    <CurrentNodeStyle CssClass="header" Font-Underline="False" ForeColor="Black" />
                                    <NodeStyle CssClass="header" ForeColor="#990000" />
                                    <RootNodeStyle CssClass="header" ForeColor="Maroon" />
                                </asp:SiteMapPath></div>
                            </td>
                            <td>
                                <div align="right">    <asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="maintext" />
                            </div></td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align: left">
                                <table align="center" cellpadding="0" class="style2" style="width: 99%">
                                    <tr>
                                        <td>
                                            <table cellpadding="0" class="style2">
                                                <tr>
                                                    <td>
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <span class="style5">Select a Company:</span>
                                                        <asp:DropDownList 
                                                            ID="DropDownList1" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            ForeColor="Maroon"
                                                            AutoPostBack="True"
                                                            onSelectedIndexChanged="DropDownList1_SelectedIndexChanged" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td
                                                        <span class="maintext"><b>Select a Contact:</b> &nbsp;</span>&nbsp;
                                                        <asp:DropDownList 
                                                            ID="DropDownList2" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            ForeColor="Maroon"
                                                            AutoPostBack="True"
                                                            onSelectedIndexChanged="DropDownList2_SelectedIndexChanged" />
                                                        <asp:Label ID="labelSelection" 
                                                            runat="server" style="z-index: 102; left: 368px; position: absolute; top: 144px">
                                                        </asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style6">
                                                        <asp:HyperLink 
                                                            ID="AddCompany" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            Font-Bold="True" 
                                                            ForeColor="Maroon" 
                                                            NavigateUrl="~/ServiceExpress/DisAddCo.aspx">Add New Company?</asp:HyperLink>
                                                        <br />
                                                        <br />
                                                        <asp:FormView ID="FormView1" runat="server" DefaultMode="Insert" 
                                                            DataSourceID="SqlDataSource4">
                                                            <InsertItemTemplate>
                                                                <table cellpadding="0" class="style2">
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Company:</td>
                                                                        <td colspan="5" style="margin-left: 40px">
                                                                            <asp:TextBox ID="Company" runat="server" Width="250px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Phone:</td>
                                                                        <td>
                                                                            <asp:TextBox ID="Phone" runat="server" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            First Name:</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="FirstName" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Last Name:
                                                                        </td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="LastName" runat="server" style="margin-bottom: 0px" 
                                                                                Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Technician:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListTech" runat="server" CssClass="maintext" 
                                                                        DataSourceID="SqlDataSource3" DataTextField="techid" 
                                                                        DataValueField="UserID" AppendDataBoundItems="True">
                                                                        <asp:ListItem Value="">Unassigned</asp:ListItem>
                                                                         </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Address:</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="Address1" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Priority:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListPriority" runat="server" CssClass="maintext">
                                                                                <asp:ListItem Selected="True">Select One</asp:ListItem>
                                                                                <asp:ListItem>Red (High)</asp:ListItem>
                                                                                <asp:ListItem>Yellow</asp:ListItem>
                                                                                <asp:ListItem>Blue</asp:ListItem>
                                                                                <asp:ListItem>Green (Low)</asp:ListItem>
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style15">
                                                                            &nbsp;</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="Address2" runat="server" Width="200px" 
                                                                                style="margin-bottom: 0px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Billing:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListBill" runat="server" CssClass="maintext">
                                                                                <asp:ListItem Selected="True">Select One</asp:ListItem>
                                                                                <asp:ListItem>Contract</asp:ListItem>
                                                                                <asp:ListItem>Time/Materials</asp:ListItem>
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            City:</td>
                                                                        <td class="style14">
                                                                            <asp:TextBox ID="City" runat="server" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            State:</td>
                                                                        <td class="style12">
                                                                            <asp:TextBox ID="State" runat="server" Width="30px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Zip:</td>
                                                                        <td class="style11">
                                                                            <asp:TextBox ID="Zip" runat="server" Width="80px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style16">
                                                                            </td>
                                                                        <td class="style17">
                                                                            </td>
                                                                        <td class="style18">
                                                                            </td>
                                                                        <td class="style19">
                                                                            </td>
                                                                        <td class="style20">
                                                                            </td>
                                                                        <td class="style21">
                                                                            </td>
                                                                        <td class="style22">
                                                                            </td>
                                                                        <td class="style23">
                                                                            </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Equipment:</td>
                                                                        <td class="style14">
                                                                            <asp:DropDownList ID="DropDownListEquip" runat="server" CssClass="maintext" />
                                                                        </td>
                                                                        <td class="style13">
                                                                            &nbsp;</td>
                                                                        <td class="style12">
                                                                            &nbsp;</td>
                                                                        <td class="style9">
                                                                            &nbsp;</td>
                                                                        <td class="style11">
                                                                            &nbsp;</td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext" valign="top">
                                                                            Problem:</td>
                                                                        <td class="style8" colspan="5">
                                                                            <asp:TextBox ID="Problem" runat="server" Height="100px" TextMode="MultiLine" 
                                                                        Width="400px"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext" valign="top">
                                                                            Notes:</td>
                                                                        <td>
                                                                            <asp:TextBox ID="Notes" runat="server" Height="100px" TextMode="MultiLine" 
                                                                        Width="400px"></asp:TextBox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style7" colspan="8" valign="top">
                                                                            <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
                                                                            &nbsp;<asp:Button ID="Button2" runat="server" Text="Reset" />
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </InsertItemTemplate>
                                                        </asp:FormView>
                                                        <asp:SqlDataSource ID="SqlDataSource4" runat="server"></asp:SqlDataSource>
                                                        <br />
                                                        &nbsp;<br />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>

                                <asp:SqlDataSource 
                                    ID="SqlDataSource3" 
                                    runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:HRIServiceConnectionString1 %>"                                
                                    SelectCommand="SELECT [UserID], [FirstName]+ ' ' + [LastName] AS techid FROM [aspnet_Users] WHERE [isTech] = 'True' ORDER BY [LastName], [FirstName]">
                                </asp:SqlDataSource>
                            </td>
                        </tr>
                    </table>
                    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
                </td>
            </tr>
        </table>
</asp:Content>

erver Error in '/HRIService' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'Company' is not declared.

Source Error:

Line 46: If reader.HasRows Then
Line 47: While reader.Read()
Line 48: Company.Text = reader("Company").ToString
Line 49: Address1.Text = reader("Address1").ToString
Line 50: Address2.Text = reader("Address2").ToString


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx Line: 48

Here try this code, sorry forgot something:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" title="Hackworth Reprographics Service Express - Add Call" %>
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.Data.SqlClient" %>

<script language="vb" runat="server">
    Dim conn As New SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
    Dim cmd As SqlCommand
    Dim reader As SqlDataReader
    Dim reader2 As SqlDataReader

    Public Sub Page_Load(ByVal S As Object, ByVal E As EventArgs)

        If Not Page.IsPostBack Then

            Dim bol As Boolean = False
            Dim conID As String = Trim(Request.QueryString("conID")).ToString()
            Dim cusID As String = Trim(Request.QueryString("cusID")).ToString()

            If Len(cusID) > 0 And Len(conID) > 0 Then

                ' Try
                cmd = New SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
                cmd.Parameters.AddWithValue("@cusID", cusID)

                conn.Open()
                reader = cmd.ExecuteReader()

                If reader.HasRows Then
                    DropDownList2.DataSource = reader
                    DropDownList2.DataTextField = "ContactName"
                    DropDownList2.DataValueField = "cusID"
                    DropDownList2.DataBind()
                    DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
                    DropDownList2.SelectedIndex = DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(conID))
                Else
                    DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --"))
                End If

                reader.Close()

                cmd = New SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
                cmd.Parameters.AddWithValue("@cusID", cusID)
                cmd.Parameters.AddWithValue("@ContactID", conID)
                reader2 = cmd.ExecuteReader()

                If reader.HasRows Then
                    While reader.Read()
                        Company.Text = reader("Company").ToString
                        Address1.Text = reader("Address1").ToString
                        Address2.Text = reader("Address2").ToString
                        Phone.Text = reader("Phone").ToString
                        FirstName.Text = reader("FirstName").ToString()
                        LastName.Text = reader("LastName").ToString()
                        City.Text = reader("City").ToString()
                        State.Text = reader("State").ToString()
                        Zip.Text = reader("Zip").ToString()
                    End While
                End If

                reader.Close()
                conn.Close()
                '  Catch
                ' End Try

                bol = True

            End If

            cmd = New SqlCommand("SELECT cusID, Company FROM Customers", conn)

            ' Try
            conn.Open()
            reader = cmd.ExecuteReader()

            If reader.HasRows Then
                DropDownList1.DataSource = reader
                DropDownList1.DataTextField = "Company"
                DropDownList1.DataValueField = "cusID"
                DropDownList1.DataBind()
                DropDownList1.Items.Insert(0, ("-- Choose a Company --"))
                If bol = True Then DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(conID))
            Else
                DropDownList1.Items.Insert(0, ("-- Error: No Companies Found --"))
            End If

            reader.Close()
            conn.Close()
            ' Catch
            ' End Try

        End If

    End Sub


    Public Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        ' Try
        cmd = New SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

        conn.Open()
        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            DropDownList2.DataSource = reader
            DropDownList2.DataTextField = "ContactName"
            DropDownList2.DataValueField = "cusID"
            DropDownList2.DataBind()
            DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
        Else
            DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --"))
        End If

        reader.Close()

        cmd = New SqlCommand("SELECT a.Company + ' - ' + b.Description As CompanyEqpDesc, b.eqpID FROM Manufacturers a JOIN Equipment b ON a.mfgID=b.mfgID WHERE b.eqpID IN (SELECT eqpID FROM Cus_Equip WHERE cusID=@cusID)", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

        reader2 = cmd.ExecuteReader()

        If reader.HasRows Then
            DropDownListEquip.DataSource = reader
            DropDownListEquip.DataTextField = "CompanyEqpDesc"
            DropDownListEquip.DataValueField = "eqpID"
            DropDownListEquip.DataBind()
            DropDownListEquip.Items.Insert(0, ("-- Choose Equipment --"))
        Else
            DropDownListEquip.Items.Insert(0, ("-- Error: No Equipment Found --"))
        End If

        reader.Close()
        conn.Close()
        ' Catch
        '  End Try

        FirstName.Text = ""
        LastName.Text = ""

    End Sub


    Public Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        cmd = New SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
        cmd.Parameters.AddWithValue("@conID", DropDownList2.SelectedValue)

        ' Try
        conn.Open()
        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            While reader.Read()
                Company.Text = reader("Company").ToString
                Address1.Text = reader("Address1").ToString
                Address2.Text = reader("Address2").ToString
                Phone.Text = reader("Phone").ToString
                FirstName.Text = reader("FirstName").ToString()
                LastName.Text = reader("LastName").ToString()
                City.Text = reader("City").ToString()
                State.Text = reader("State").ToString()
                Zip.Text = reader("Zip").ToString()
            End While
        End If

        reader.Close()
        conn.Close()
        ' Catch
        'End Try

    End Sub


    Public Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim disID As String
        Dim recs As Integer = 0

        cmd = New SqlCommand("INSERT INTO Dispatch (cusID, Problem, Priority, Contract) VALUES (@cusID, @Problem, @Priority, @Contract); SELECT SCOPE_IDENTITY()", conn)
        cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedItem.Value)
        cmd.Parameters.AddWithValue("@Problem", Trim(Problem.Text))
        cmd.Parameters.AddWithValue("@Priority", DropDownListPriority.SelectedItem.Text)
        cmd.Parameters.AddWithValue("@Contract", DropDownListBill.SelectedItem.Text)

        '   Try
        conn.Open()
        disID = cmd.ExecuteScalar()

        cmd = New SqlCommand("INSERT INTO DispatchEvents (disID, Notes) VALUES (@disID, @Notes)", conn)
        cmd.Parameters.AddWithValue("@disID", disID)
        cmd.Parameters.AddWithValue("@Notes", Trim(Notes.Text))

        recs = cmd.ExecuteNonQuery()
        conn.Close()

        If Len(disID) > 0 Then recs += 1

        If recs > 1 Then
            Response.Redirect("Dispatch.aspx")
        Else
            Response.Write("Recs Counted: " & recs & " out of 2.")
        End If
        ' Catch ex As SqlException
        ' Response.Write(ex)
        ' End Try

    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style5
        {
            font-family: Verdana;
            font-size: 12px;
            color: #000000;
            text-align: left;
            font-weight: bold;
        }
        .style6 { height: 20px; }
        .style7 { }
        .style8 { }
        .style9 { width: 26px; }
        .style10 { width: 79px; }
        .style11 { width: 134px; }
        .style12 { width: 50px; }
        .style13 { width: 40px; }
        .style14 { width: 149px; }
        .style15 { width: 86px; }
        .style16
        {
            width: 86px;
            height: 22px;
        }
        .style17
        {
            width: 149px;
            height: 22px;
        }
        .style18
        {
            width: 40px;
            height: 22px;
        }
        .style19
        {
            width: 50px;
            height: 22px;
        }
        .style20
        {
            width: 26px;
            height: 22px;
        }
        .style21
        {
            width: 134px;
            height: 22px;
        }
        .style22
        {
            width: 79px;
            height: 22px;
        }
        .style23 { height: 22px; }
    </style>
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table width="100%" cellpadding="0" cellspacing="0" class="topblack">
            <tr>
                <td width="177px" class="rightborder" bgcolor="#CCCCCC" valign="top">
                    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" 
                        ImageSet="Arrows" style="text-align: left">
                        <ParentNodeStyle Font-Bold="False" />
                        <HoverNodeStyle Font-Underline="True" ForeColor="Maroon" />
                        <SelectedNodeStyle Font-Underline="True" ForeColor="Maroon" 
                            HorizontalPadding="0px" VerticalPadding="0px" />
                        <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" 
                            HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
                    </asp:TreeView>
                    <br />
                </td>
                <td valign="top">
                   
                    <table cellspacing="2" cellpadding="0" width="100%">
                        <tr>
                            <td>
                                <div align="left"><asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" | ">
                                    <CurrentNodeStyle CssClass="header" Font-Underline="False" ForeColor="Black" />
                                    <NodeStyle CssClass="header" ForeColor="#990000" />
                                    <RootNodeStyle CssClass="header" ForeColor="Maroon" />
                                </asp:SiteMapPath></div>
                            </td>
                            <td>
                                <div align="right">    <asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="maintext" />
                            </div></td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align: left">
                                <table align="center" cellpadding="0" class="style2" style="width: 99%">
                                    <tr>
                                        <td>
                                            <table cellpadding="0" class="style2">
                                                <tr>
                                                    <td>
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <span class="style5">Select a Company:</span>
                                                        <asp:DropDownList 
                                                            ID="DropDownList1" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            ForeColor="Maroon"
                                                            AutoPostBack="True"
                                                            onSelectedIndexChanged="DropDownList1_SelectedIndexChanged" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td
                                                        <span class="maintext"><b>Select a Contact:</b> &nbsp;</span>&nbsp;
                                                        <asp:DropDownList 
                                                            ID="DropDownList2" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            ForeColor="Maroon"
                                                            AutoPostBack="True"
                                                            onSelectedIndexChanged="DropDownList2_SelectedIndexChanged" />
                                                        <asp:Label ID="labelSelection" 
                                                            runat="server" style="z-index: 102; left: 368px; position: absolute; top: 144px">
                                                        </asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style6">
                                                        <asp:HyperLink 
                                                            ID="AddCompany" 
                                                            runat="server" 
                                                            CssClass="maintext" 
                                                            Font-Bold="True" 
                                                            ForeColor="Maroon" 
                                                            NavigateUrl="~/ServiceExpress/DisAddCo.aspx">Add New Company?</asp:HyperLink>
                                                        <br />
                                                        <br />
                                                                <table cellpadding="0" class="style2">
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Company:</td>
                                                                        <td colspan="5" style="margin-left: 40px">
                                                                            <asp:TextBox ID="Company" runat="server" Width="250px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Phone:</td>
                                                                        <td>
                                                                            <asp:TextBox ID="Phone" runat="server" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            First Name:</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="FirstName" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Last Name:
                                                                        </td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="LastName" runat="server" style="margin-bottom: 0px" 
                                                                                Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Technician:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListTech" runat="server" CssClass="maintext" 
                                                                        DataSourceID="SqlDataSource3" DataTextField="techid" 
                                                                        DataValueField="UserID" AppendDataBoundItems="True">
                                                                        <asp:ListItem Value="">Unassigned</asp:ListItem>
                                                                         </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Address:</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="Address1" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Priority:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListPriority" runat="server" CssClass="maintext">
                                                                                <asp:ListItem Selected="True">Select One</asp:ListItem>
                                                                                <asp:ListItem>Red (High)</asp:ListItem>
                                                                                <asp:ListItem>Yellow</asp:ListItem>
                                                                                <asp:ListItem>Blue</asp:ListItem>
                                                                                <asp:ListItem>Green (Low)</asp:ListItem>
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style15">
                                                                            &nbsp;</td>
                                                                        <td colspan="5">
                                                                            <asp:TextBox ID="Address2" runat="server" Width="200px" 
                                                                                style="margin-bottom: 0px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Billing:</td>
                                                                        <td>
                                                                            <asp:DropDownList ID="DropDownListBill" runat="server" CssClass="maintext">
                                                                                <asp:ListItem Selected="True">Select One</asp:ListItem>
                                                                                <asp:ListItem>Contract</asp:ListItem>
                                                                                <asp:ListItem>Time/Materials</asp:ListItem>
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            City:</td>
                                                                        <td class="style14">
                                                                            <asp:TextBox ID="City" runat="server" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            State:</td>
                                                                        <td class="style12">
                                                                            <asp:TextBox ID="State" runat="server" Width="30px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext">
                                                                            Zip:</td>
                                                                        <td class="style11">
                                                                            <asp:TextBox ID="Zip" runat="server" Width="80px" ReadOnly="True"></asp:TextBox>
                                                                        </td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style16">
                                                                            </td>
                                                                        <td class="style17">
                                                                            </td>
                                                                        <td class="style18">
                                                                            </td>
                                                                        <td class="style19">
                                                                            </td>
                                                                        <td class="style20">
                                                                            </td>
                                                                        <td class="style21">
                                                                            </td>
                                                                        <td class="style22">
                                                                            </td>
                                                                        <td class="style23">
                                                                            </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext">
                                                                            Equipment:</td>
                                                                        <td class="style14">
                                                                            <asp:DropDownList ID="DropDownListEquip" runat="server" CssClass="maintext" />
                                                                        </td>
                                                                        <td class="style13">
                                                                            &nbsp;</td>
                                                                        <td class="style12">
                                                                            &nbsp;</td>
                                                                        <td class="style9">
                                                                            &nbsp;</td>
                                                                        <td class="style11">
                                                                            &nbsp;</td>
                                                                        <td class="style10">
                                                                            &nbsp;</td>
                                                                        <td>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="maintext" valign="top">
                                                                            Problem:</td>
                                                                        <td class="style8" colspan="5">
                                                                            <asp:TextBox ID="Problem" runat="server" Height="100px" TextMode="MultiLine" 
                                                                        Width="400px"></asp:TextBox>
                                                                        </td>
                                                                        <td class="maintext" valign="top">
                                                                            Notes:</td>
                                                                        <td>
                                                                            <asp:TextBox ID="Notes" runat="server" Height="100px" TextMode="MultiLine" 
                                                                        Width="400px"></asp:TextBox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="style7" colspan="8" valign="top">
                                                                            <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
                                                                            &nbsp;<asp:Button ID="Button2" runat="server" Text="Reset" />
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                        <br />
                                                        &nbsp;<br />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>

                                <asp:SqlDataSource 
                                    ID="SqlDataSource3" 
                                    runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:HRIServiceConnectionString1 %>"                                
                                    SelectCommand="SELECT [UserID], [FirstName]+ ' ' + [LastName] AS techid FROM [aspnet_Users] WHERE [isTech] = 'True' ORDER BY [LastName], [FirstName]">
                                </asp:SqlDataSource>
                            </td>
                        </tr>
                    </table>
                    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
                </td>
            </tr>
        </table>
</asp:Content>

When I chose the company ddl this happened:
Server Error in '/HRIService' Application.
Invalid attempt to call HasRows when reader is closed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Invalid attempt to call HasRows when reader is closed.

Source Error:

Line 120: reader2 = cmd.ExecuteReader()
Line 121:
Line 122: If reader.HasRows Then
Line 123: DropDownListEquip.DataSource = reader
Line 124: DropDownListEquip.DataTextField = "CompanyEqpDesc"


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx Line: 122

Yup, look at the code:

Line 120: reader2 = cmd.ExecuteReader()
Line 121:
Line 122: If reader2.HasRows Then

Add the guy in red (2). reader isn't open, but reader 2 is :)

Server Error in '/HRIService' Application.
Invalid attempt to call FieldCount when reader is closed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Invalid attempt to call FieldCount when reader is closed.

Source Error:

Line 124: DropDownListEquip.DataTextField = "CompanyEqpDesc"
Line 125: DropDownListEquip.DataValueField = "eqpID"
Line 126: DropDownListEquip.DataBind()
Line 127: DropDownListEquip.Items.Insert(0, ("-- Choose Equipment --"))
Line 128: Else


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx Line: 126

Yes yes lol.

Line 123: DropDownListEquip.DataSource = reader2

I figured that one out. Now there is this:
Server Error in '/HRIService' Application.
Must declare the scalar variable "@conID".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@conID".

Source Error:

Line 42: cmd.Parameters.AddWithValue("@cusID", cusID)
Line 43: cmd.Parameters.AddWithValue("@ContactID", conID)
Line 44: reader2 = cmd.ExecuteReader()
Line 45:
Line 46: If reader.HasRows Then


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx Line: 44

Keep in mind, your queries are setup so that they ALWAYS return something, whether or not it's DBNull or an actual record.

With it meaning that it is out of range, means that it is most likely a null value in your database.

To make sure that it always returns a value, then you do this:
"SELECT COALESCE(Phone, 'ValueToReturnIfPhoneIsNull') As Phone FROM ..."

Otherwise use the DBNull command to detect if it is null.

This just means that the record you pulled has a null reference in column "Phone". Add a value there and test again.

I fixed that. It Phone was not in the select statement. This is the new error:
Server Error in '/HRIService' Application.
Must declare the scalar variable "@conID".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@conID".

Source Error:

Line 42: cmd.Parameters.AddWithValue("@cusID", cusID)
Line 43: cmd.Parameters.AddWithValue("@ContactID", conID)
Line 44: reader2 = cmd.ExecuteReader()
Line 45:
Line 46: If reader.HasRows Then


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx Line: 44

Yeah, change line 43 @ConctactID to @conID

I had some tell me this. Is it a valid question?

In this line here
Code:

cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)

Check and make sure that DropDownList1.SelectedValue is not null

Your page is so crowded, you may divide your pages into web user controls so specific part of the pages can do certain jobs. Try using stored procedures instead of inline t-sql statements, put your business logic into class files instead of codebehind files. Your page is so long that we can not easily see where the error occurs.

That sounds like an excellent idea, other than that I don't know how to do all that so that it would work together. I know about stored procedures but the class files is a new concept.

Actually, if you start working with 4 tiered application architecture, you would do all that i mentioned. Seperate the code for accessing the data from your presentation layer. Create a Data Access layer first. You can do that easily by using built-in visual studio dataset designer. Add DataSet to your project, then configure the tableAdapter by using the opening wizard. This creates the entity classes and DataAccess logic for you, this also creates the stored procedures if you choose so. Then in your .aspx pages do only databinding and setting datasource of your controls to your dataobject which is created for you. If you drag and drop objectDataSource, its wizard will automatically display the dataobjects for you. Then you can choose from one. Just try it you will see it is so easy.

I started setting up the DAL and all that initially but I ran into problems setting up my db in the App_Data folder. It wasn't working the way it was supposed to. I don't remember all the details, but at the time all the new info was a little overwhelming for me.

There are video tutorials about building up your DAL in www.asp.net . Set aside time for it, you will see it helps a lot.

Yeah, that is what I was doing when I was trying to set it up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.