Solved

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

Posted on 2009-07-14
2
444 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

831 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