PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED]Correct my sql statement well now more like help!-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED]Correct my sql statement well now more like help!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    79

    [RESOLVED]Correct my sql statement well now more like help!

    Hi there i have this sql statement and i cant get it to work properly

    "SELECT * FROM Employee WHERE '" & Combo1.Text & "' = '" & text1.Text & "'"

    i want it to select everything from the table employee where the value of the combobox equals the text1 field.

    this seems to bring back all of the fields for some reason

    cheers

    ed
    Last edited by golyath; Feb 17th, 2005 at 03:26 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: Correct my sql statement

    You don't have to inclose field name into quotes:

    strSQL = "SELECT * FROM Employee WHERE " & Combo1.Text & " = '" & text1.Text & "'"

    Also, before you execute your sql statement check it in debug (perhaps by placing break pointer directly on that line).

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    79

    Re: Correct my sql statement

    Hmmm... this still returns everything in the table and not just the fields i want....

    Heres the code:

    VB Code:
    1. Private Sub view_all_Click()Private Sub view_all_Click()
    2.     Dim cn As ADODB.Connection
    3.     Dim rs As ADODB.Recordset
    4.     Set cn = New ADODB.Connection
    5.     Set rs = New ADODB.Recordset
    6.     cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= clockDB.mdb ;Persist Security Info=False"
    7.     rs.CursorLocation = adUseClient
    8.     rs.Open "SELECT * FROM Employee WHERE " & Combo1.Text & " = '" & text1.Text & "'", cn, adOpenKeyset, adLockReadOnly, adCmdText
    9.     If rs.RecordCount = 0 Then
    10.         MsgBox "No records returned"
    11.         Exit Sub
    12.     End If
    13.     Set DataGrid1.DataSource = rs
    14.     DataGrid1.Refresh
    15. End Sub

    could anyone help why this returns everything....

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,864

    Re: Correct my sql statement

    SELECT * means all columns - that is what the * means.

    If you want specific columns, then say SELECT COL1, COL2, COL3 FROM

    BTW - it's bad practice to use SELECT * in production code - in my opinion, you always specify column names.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    79

    Re: Correct my sql statement

    Sorry im just trying to do this for a school project....

    i want all of the columns to show...

    im trying to write some code that searches a database. so that you can choose from the combox what you want to search by e.g LastName or FirstName. then you put your search criterea in the textbox....

    e.g search where last name = jones

    could anyone help?

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width