Ah blah.

Is ContactID an auto-increment, IDENTITY field? It should return the ID that was created.

I got rid of the contactID field yesterday when we were fixing the updating multiple tables.

oh hmm, let me look at the db design again. I'll get back to you in a second.

Alright quick question.

Is each company allowed to have more than 1 contact? If so, you need the ContactID field back in there with an auto-increment. Make it the primary.

If not, then let me know and I'll give you updated code.

Yes, each company can have multiple contacts.

Ok, add the new column ContactID with the IDENTITY and auto increment, set it Primary:

ALTER TABLE Contacts ADD ContactID int IDENTITY(1,1) PRIMARY KEY

the IDENTITY(#,#): First number is the starting number. Start at 1000, increment by 5:
IDENTITY(1000,5)

I got that done. I"m using SQL Server Management Express Studio. So, I just did it in design mode.

Ok, it inserted the record with no errors but it did not populate the ticket fields.

Yeah I misspelled something in this line. Try it again:

if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then

Still nothing ...

I never put this anywhere. Is it supposed to go somewhere?

Dim cusID As String = Trim(Request.QueryString("cusID"))
Dim conID As String = Trim(Request.QueryString("conID"))
DropDownList1.Items.FindByValue(cusID).Selected = True
Dim eventarg As New EventArgs
Call DropDownList1_SelectedIndexChanged(DropDownList1, eventarg.Empty)
DropDownList2.Items.FindByValue(conID).Selected = True
eventarg = New EventArgs
Call DropDownList2_SelectedIndexChanged(DropDownList2, eventarg.Empty)

Partial Class AddCall
    Inherits System.Web.UI.Page


    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)
        DropDownList2.SelectedIndex = 0
        FirstName.Text = ""
        LastName.Text = ""
    End Sub


    Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text

        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 str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
        Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")

            Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)

            Try
                connection.Open()
                Dim reader As System.Data.SqlClient.SqlDataReader = command.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
                    end while
                End If
                reader.Close()


                str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
                command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
                reader = command.ExecuteReader()

                If reader.HasRows then
                    while reader.Read()
                        FirstName.Text = reader.Item("FirstName").ToString()
                        LastName.Text = reader.Item("LastName").ToString()
                    end while
                End If
                reader.Close()


                str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
                command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
                reader = command.ExecuteReader()

                If reader.HasRows then
                    while reader.Read()
                        City.Text = reader.Item("City").ToString()
                        State.Text = reader.Item("State").ToString()
                        Zip.Text = reader.Item("Zip").ToString()
                    end while
                End If
                reader.Close()
                connection.Close()
            Catch ex As System.Data.SqlClient.SqlException
            End Try

        End Using

    End Sub


    Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
        Dim cusID As String = Trim(Request.QueryString("cusID"))
        Dim conID As String = Trim(Request.QueryString("conID"))

        if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
            DropDownList1.Items.FindByValue(cusID).Selected = True
            Dim eventarg As New EventArgs
            Call DropDownList1_SelectedIndexChanged(DropDownList1, eventarg.Empty)

            DropDownList2.Items.FindByValue(conID).Selected = True
            eventarg = New EventArgs
            Call DropDownList2_SelectedIndexChanged(DropDownList2, eventarg.Empty)
        end if
    End Sub

    Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

End Class

It's updating but not posting to the fields.

Sorry, the DropDownLists are updating, but nothing goes to the fields?

No, its being inserted into the db but nothing is showing on the add ticket page, no ddls, no fields.

nothing showing, or nothing set? there's a difference. I'll get back to you asap this time lol

When you click to add new customer it redirects to the add ticket page, put none of the ddls or fields are filled with the previous form.

Damn I was hoping it would call the selectedindexchanged. Let me look it up and see if I got it wrong. I'll be right back.

replace the page_load method with this:

Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
        Dim cusID As String = Trim(Request.QueryString("cusID"))
        Dim conID As String = Trim(Request.QueryString("conID"))

        if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
            DropDownList1.Items.FindByValue(cusID).Selected = True
            RaiseEvent DropDownList1_SelectedIndexChanged(DropDownList1, e)

            DropDownList2.Items.FindByValue(conID).Selected = True
            RaiseEvent DropDownList2_SelectedIndexChanged(DropDownList2, e)
        end if
    End Sub

I now get this error...

Server 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: BC30269: 'Protected Sub Page_Load(S As Object, E As System.EventArgs)' has multiple definitions with identical signatures.

Source Error:

Line 1: Partial Class AddCall
Line 2: Inherits System.Web.UI.Page
Line 3: Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
Line 4: Dim cusID As String = Trim(Request.QueryString("cusID"))
Line 5: Dim conID As String = Trim(Request.QueryString("conID"))


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

You have to replace them. You can only have one sub page_load :)

That error says you have more than 1 "Page_Load"

I put a page load at the bottom of the page of your last script. Remove that page load, and insert this one.

Now it says:

Server 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: BC30676: 'DropDownList1_SelectedIndexChanged' is not an event of 'AddCall'.

Source Error:

Line 83: If Not cusID Is Nothing And Not conID Is Nothing And Len(cusID) > 1 And Len(conID) > 1 Then
Line 84: DropDownList1.Items.FindByValue(cusID).Selected = True
Line 85: RaiseEvent DropDownList1_SelectedIndexChanged(DropDownList1, e)
Line 86:
Line 87: DropDownList2.Items.FindByValue(conID).Selected = True


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

does the event have to be defined?

What I am trying to do is to call those events so that you don't have to have code written in different areas that do the same thing.

If all else fails, we will just put more code in there.

Gotcha, what is the next course of action?

I am asking serk (another user on here that knows his stuff), if he knows of a way to make it call the event. I have never had to do it, therefore I am shooting in the dark.

Oh duh, why didn't that click? Here, try this:

Partial Class AddCall
    Inherits System.Web.UI.Page


    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)
        DropDownList2.SelectedIndex = 0
        FirstName.Text = ""
        LastName.Text = ""
    End Sub


    Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text

        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 str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
        Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")

            Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)

            Try
                connection.Open()
                Dim reader As System.Data.SqlClient.SqlDataReader = command.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
                    end while
                End If
                reader.Close()


                str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
                command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
                reader = command.ExecuteReader()

                If reader.HasRows then
                    while reader.Read()
                        FirstName.Text = reader.Item("FirstName").ToString()
                        LastName.Text = reader.Item("LastName").ToString()
                    end while
                End If
                reader.Close()


                str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
                command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
                reader = command.ExecuteReader()

                If reader.HasRows then
                    while reader.Read()
                        City.Text = reader.Item("City").ToString()
                        State.Text = reader.Item("State").ToString()
                        Zip.Text = reader.Item("Zip").ToString()
                    end while
                End If
                reader.Close()
                connection.Close()
            Catch ex As System.Data.SqlClient.SqlException
            End Try

        End Using

    End Sub


    Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
        Dim cusID As String = Trim(Request.QueryString("cusID"))
        Dim conID As String = Trim(Request.QueryString("conID"))

        if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
            DropDownList1.Items.FindByValue(cusID).Selected = True
            DropDownList1_SelectedIndexChanged(DropDownList1, e)

            DropDownList2.Items.FindByValue(conID).Selected = True
            DropDownList2_SelectedIndexChanged(DropDownList2, e)
        end if
    End Sub

    Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

End Class

Now we have this:

Server 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: BC30455: Argument not specified for parameter 'e' of 'Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs)'.

Source Error:

Line 85: If Not cusID Is Nothing And Not conID Is Nothing And Len(cusID) > 1 And Len(conID) > 1 Then
Line 86: DropDownList1.Items.FindByValue(cusID).Selected = True
Line 87: DropDownList1_SelectedIndexChanged()
Line 88:
Line 89: DropDownList2.Items.FindByValue(conID).Selected = True


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

I updated it, copy and paste again.

Didn't know you were that quick :O

Next time wait 10 seconds LOL

Still did not populate the add ticket fields. Just a blank form after adding the customer.

Try this and let me know what number it displays at on the page:

Partial Class AddCall
    Inherits System.Web.UI.Page


    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)
        DropDownList2.SelectedIndex = 0
        FirstName.Text = ""
        LastName.Text = ""
    End Sub


    Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text

        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 str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
        Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")

            Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)

            Try
                connection.Open()
                Dim reader As System.Data.SqlClient.SqlDataReader = command.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
                    end while
                End If
                reader.Close()


                str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
                command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
                reader = command.ExecuteReader()

                If reader.HasRows then
                    while reader.Read()
                        FirstName.Text = reader.Item("FirstName").ToString()
                        LastName.Text = reader.Item("LastName").ToString()
                    end while
                End If
                reader.Close()


                str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
                command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
                reader = command.ExecuteReader()

                If reader.HasRows then
                    while reader.Read()
                        City.Text = reader.Item("City").ToString()
                        State.Text = reader.Item("State").ToString()
                        Zip.Text = reader.Item("Zip").ToString()
                    end while
                End If
                reader.Close()
                connection.Close()
            Catch ex As System.Data.SqlClient.SqlException
            End Try

        End Using

    End Sub


    Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
        Dim cusID As String = Trim(Request.QueryString("cusID"))
        Dim conID As String = Trim(Request.QueryString("conID"))

        if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
response.write("11111111111111111111111111")
            DropDownList1.Items.FindByValue(cusID).Selected = True
            DropDownList1_SelectedIndexChanged(DropDownList1, e)

            DropDownList2.Items.FindByValue(conID).Selected = True
            DropDownList2_SelectedIndexChanged(DropDownList2, e)
else
response.write("22222222222222222222222222")
        end if
    End Sub

    Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

End Class
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.