Results 1 to 3 of 3

Thread: Updating DataGridView

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Updating DataGridView

    I'm new to SQL and I'm having problems getting a search function to work with the data grid view. I've got a form set up for the search function with multiple text boxes for the user to enter information and a function that performs that search via the table adapter. My search function looks like this:
    Code:
    SELECT     Amount, Date, Department, PO_Numbers, Requester
    FROM         PO
    WHERE     (Amount = 'txtSearchAmount.Text') OR
                          (Requester = 'txtSearchRequester.Text') OR
                          (Department = 'txtSearchDepartment.Text') OR
                          (PO_Numbers = 'txtSearchPO.Text')
    ORDER BY PO_Numbers DESC
    I can't figure out how to get that result to display in the data grid view though. Any suggestions as to how to resolve this, or a better way to achieve the same result would be greatly appreciated. Thanks in advance.

    Edit: Forgot to mention I'm using visual studio 2005, and sql server 2005.
    Last edited by systemwolf; Nov 19th, 2007 at 02:59 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Updating DataGridView

    When creating a dynamic sql string you need to append the Values of the textboxes to the string.

    Code:
    Dim strSQL as String = "SELECT Amount, Date, Department, PO_Numbers, 
    Requester FROM PO WHERE  (Amount = " & txtSearchAmount.Text & ") Or (Requester = '" & txtSearchRequester.Text & "') Or ..."
    Also, do not delimit numeric values within single quotes.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Re: Updating DataGridView

    Thanks for the help! I got that updated, but how do I set the data grid viewer to show that result? I thought it would be:
    Code:
    Me.DataGridView1.DataSource = POTableAdapter.Search
    but no such luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width