Solved

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

Posted on 2009-07-14
2
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 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