Solved

Select statement in VB.NET for SQL Mobile not working... works in Query Analyzer

Posted on 2009-07-14
2
443 Views
Last Modified: 2013-12-05
I can run the following statement in Query Analyzer and get the result I am looking for.  However, when I run it in VB.NET, I get no results.  Why?

SELECT STR_NAM From LocID Where STR_NAM like '%ROAD%'
Public Shared Function GetLocs() As DataSet

 

        ' Return set of locations based on search criterion entered on LocInqScreen

 

        ' Create a connection to the Mobile SQL database

        Dim PAConnection As New SqlCeConnection

        PAConnection.ConnectionString = "Data Source =""Program Files\HTE_Apps\CT Database.sdf"""

 

        ' Define a Query and Adapter to select this screen's controls from the database

 

        'Define select string

        Dim SelectLocs As String = "SELECT STR_DIR as DIR, STR_NUM as NUM, STR_NAM as STREET, STR_SFX as SFX, CITY, STATE, ZIP, LOC_ID From LocID Where"

 

        'Define select string for each search criteria entered

 

        'Street Name

        If LocInqScreen.gSTR_NAM > "" Then

            SelectLocs = Trim(SelectLocs) + " STR_NAM like '%" + Trim(LocInqScreen.gSTR_NAM.ToString) + "%' "

        End If

 

        Dim adapter As SqlCeDataAdapter = New SqlCeDataAdapter(SelectLocs, PAConnection)

 

        ' Initiate a Dataset to contain the table returned

        Dim result As New DataSet

 

        'Fill the dataset

        PAConnection.Open()

        adapter.Fill(result, "LocID")

        PAConnection.Close()

 

        ' Return the dataset

        Return result

 

    End Function

Open in new window

0
Comment
Question by:gregdoyon
2 Comments
 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24855636
Try this one...

Trim(SelectLocs) & " STR_NAM like '%" & Trim(LocInqScreen.gSTR_NAM.ToString) & "%'"
0
 

Author Closing Comment

by:gregdoyon
ID: 31603519
Solved the problem
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now