Creating a Search in asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wbrands2
    New Member
    • Aug 2008
    • 2

    Creating a Search in asp.net

    I have a basic web form that inserts information into a ms sql database and I am trying to create a search page for it. I am running into the problem that after I insert the information into the web form page, submit it, and go to my search page the newly entered information doesn't show as part of the results. If I look in management studio I see the newly entered data is there, but for some reason I can't get it to show up on the gridview on my search page. This is the code behind my search page. What am I doing wrong?

    Code:
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
            'Initializes a string with the necessary select statement for a unique search
            Dim searchString As String = "SELECT tblPersonalInformation.FirstName, tblPersonalInformation.LastName, tblAppointmentInformation.Status, tblAppointmentInformation.MembershipType, tblAppointmentInformation.StartDate FROM tblPersonalInformation, tblAppointmentInformation WHERE tblPersonalInformation.MemberID = tblAppointmentInformation.MemberID"
    
            'This is the connection string for the IRB database
            dsSearch.ConnectionString = "Data Source=MEDRESEARCHSQL;Initial Catalog=IRB;User ID=wbrands2;Password=pizza123"
            gvsearch.Visible = True
            If (txtLastName.Text <> "") Then
                'Inserts the where statement for last name
                'based on whether or not it is the first part of the where clause or building onto it
                searchString = searchString + " AND [LastName] LIKE '" + txtLastName.Text + "' + '%'"
            End If
    
            'Determines whether a background is selected to search on
            If (ddlStatus.Text <> "Choose One:") Then
                'Inserts the where statement for background 
                searchString = searchString + " AND [Status] = '" + ddlStatus.Text + "'"
            End If
    
            'determines whether a affiliation is selected to search on
            If (ddlAffiliation.Text <> "Choose One:") Then
                'Inserts the where statement for Affiliation
                searchString = searchString + " AND [Affiliation] = '" + ddlAffiliation.Text + "'"
            End If
    
            'Determines whether a membership status is selected to search on
            If (ddlMembershipType.Text <> "Choose One:") Then
                'Inserts the where statement for membership status 
                searchString = searchString + " AND [MembershipType] = '" + ddlMembershipType.Text + "'"
            End If
    
            'Used in testing to see what the full SQL statement looks like
            lblSearchString.Text = searchString
            'This sets the select command equal to the search string 
            dsSearch.SelectCommand = searchString
        End Sub
    Last edited by DrBunchman; Aug 4 '08, 08:18 AM. Reason: Added [Code] Tags - Please use the '#' button
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi wbrands2

    Welcome to Bytes.com! I hope you find the site useful.

    You've posted your question in the ASP Forum which is for Classic ASP only - I've moved it for you but in future please post all ASP.NET questions in the .NET Forum.

    Also please use the # button to wrap your code in CODE tags - it makes your posts much easier to read.

    Good luck finding a solution to your problem.

    Dr B
    MODERATOR

    Comment

    Working...