Results 1 to 3 of 3

Thread: Retrieving columns of complex queries

  1. #1

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Question Retrieving columns of complex queries

    This is my SQL query that pulls and organizes the information I need linked together in one query result.
    Code:
    SELECT     TRD100_REQSEQ_EVENT.req_seq_no,                        
    
                          TPM300_PAT_VISIT.med_rec_no, TPM300_PAT_VISIT.vst_ext_id
    
                             
    
    FROM         TRD100_REQSEQ_EVENT WITH (NOLOCK) INNER JOIN
    
                          TPM300_PAT_VISIT WITH (NOLOCK) ON TRD100_REQSEQ_EVENT.vst_int_id = TPM300_PAT_VISIT.vst_int_id
    Whenever I try to run my query in VB try to read the necessary columns to strings I can't seem to get the results

    vb.net Code:
    1. Try
    2.  
    3.             conn.Open()
    4.             Dim command = New SqlCommand("SELECT TRD100_REQSEQ_EVENT.req_seq_no, TPM300_PAT_VISIT.med_rec_no, TPM300_PAT_VISIT.vst_ext_id FROM TRD100_REQSEQ_EVENT WITH (NOLOCK) INNER JOIN TPM300_PAT_VISIT WITH (NOLOCK) ON TRD100_REQSEQ_EVENT.vst_int_id = TPM300_PAT_VISIT.vst_int_id WHERE req_seq_no = '" & TxtACC.Text & "'", conn)
    5.             Dim reader As SqlDataReader = command.ExecuteReader()
    6.             While reader.Read()
    7.                 MsgBox(reader("med_rec_no").ToString)
    8.             End While
    9.             conn.Close()
    10.         Catch ex As Exception
    11.             MsgBox(ex.Message)
    12.             conn.Close()
    13.         End Try

    The query works fine in SQL Server Management... Any takers?

    Thanks much in advance!

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Retrieving columns of complex queries

    They're not quite the same query... one has a where clause while the other doesn't... try removing the where clause off of the VB version of the query.... see if you get results then.

    If you do ... two things... 1) make sure you're using a valid value for the lookup. 2) use a parameterized query instead... there's info on that in the FAQ/Tutorial section of the Database forum.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Question Re: Retrieving columns of complex queries

    Quote Originally Posted by techgnome View Post
    They're not quite the same query... one has a where clause while the other doesn't... try removing the where clause off of the VB version of the query.... see if you get results then.

    If you do ... two things... 1) make sure you're using a valid value for the lookup. 2) use a parameterized query instead... there's info on that in the FAQ/Tutorial section of the Database forum.

    -tg
    I have the WHERE clause so I can cone in on the certain instance that I specify in my textbox. I have used the query successfully with the WHERE in SQL Mgnt. Thank you for the tip I will look at the FAQ.

Tags for this Thread

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