Results 1 to 4 of 4

Thread: VB.Net/Access 2007 DB Query Problem

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    VB.Net/Access 2007 DB Query Problem

    I am brand spanking new to runtime db connections. I have a simple query problem that I can't seem to input the correct search criteria into Google find help.

    Facts:
    Using OleDB
    runtime dev

    Issue: I have a text box I want to use as the condition in which to query my Customer table and produce results in a DataGridView in VB. Everytime I execute my code I get the following: "Syntax error in string in query expression 'LastName >= (textbox contents)"

    Here is my small sub executing this query:
    Code:
        Public Sub SearchMenu()
            Dim SearchBox As String
            SearchBox = frmMain.txtName.Text
            Connection.Open()
            dvdDataSet.Clear()
            accCommand.CommandText = "SELECT * FROM Customer WHERE LastName >=' " & SearchBox
            accCommand.Connection = Connection
            dvdDataAdapter.SelectCommand = accCommand
    
            dvdDataAdapter.Fill(dvdDataSet, "Customers")
            frmMain.dvgFrmMain.DataSource = dvdDataSet.Tables("Customers")
        End Sub
    Can anyone throw me a bone on this? My Gaddis book is just completely useless on database use.

    Thanks a lot.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: VB.Net/Access 2007 DB Query Problem

    I have gotten the error reduced down to "No value given for one or more required parameters". I understand the statement but I still don't understand what I am missing in the statement. I have added everything needed. I have changed the code minimally but it still just isn't accepting it.

    New code, minimal changes:
    Code:
       Public Sub SearchMenu()
            Dim SearchBox As String
            SearchBox = frmMain.txtName.Text
            Connection.Open()
            dvdDataSet.Clear()
            accCommand.CommandText = "SELECT * FROM Customer WHERE LastName =" & SearchBox
            accCommand.Connection = Connection
            dvdDataAdapter.SelectCommand = accCommand
    
            dvdDataAdapter.Fill(dvdDataSet, "Customers")
            frmMain.dvgFrmMain.DataSource = dvdDataSet.Tables("Customers")
        End Sub
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  3. #3

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: VB.Net/Access 2007 DB Query Problem

    hahah Solved it myself!

    Code:
    accCommand.CommandText = "SELECT * FROM Customer Where LastName >= '" & SearchBox & "' ORDER BY LastName"
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB.Net/Access 2007 DB Query Problem

    That's correct now.

    For an explanation and examples of delimiters to use around values within SQL statements, see the article How do I use values (numbers, strings, dates) in SQL statements? from our Database Development FAQs/Tutorials (at the top of this forum)



    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

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