User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 427,194 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,149 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

Insert to DB & View Results on Different Page

Join Date: Sep 2007
Posts: 1,057
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Insert to DB & View Results on Different Page

  #41  
Feb 19th, 2008
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
Last edited by SheSaidImaPregy : Feb 19th, 2008 at 3:01 pm.
Reply With Quote  
All times are GMT -4. The time now is 10:22 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC