Solved

error 102

Posted on 2013-10-30
4
307 Views
Last Modified: 2013-10-31
Problem using Execute Reader
in this part of the program I want to see if there are similar names to  (vemp)  in a table.
 
Get Error number 102  " incorrect syntax near '%'  

vemp = InputBox("Digit Company name", "")
        If vemp.ToString <> "" Then

            Dim sSql As String
            Dim objConn As SqlConnection
            Dim objCmd As SqlCommand
            Dim DR As SqlDataReader
            Dim strConn As String = "server=.\SqlExpress; database=mala2; Trusted_Connection=yes"
            objConn = New SqlConnection(strConn)
            sSql = "select * from md1 where empresa like " & vemp & "%"
            objCmd = New SqlCommand(sSql, objConn)
            Try
                objConn.Open()
            Catch exc As Exception
                MessageBox.Show("Error in opening the  connection")
                Exit Sub
            End Try

ok up to here

            Try
                DR = objCmd.ExecuteReader
            Catch exc As SqlException
                Dim erro As String
                error = exc.Number.ToString + " - " + exc. Message
                MessageBox.Show(error)
                Exit Sub
            End Try

            If DR.HasRows Then  ' there are similar names, show table
                Me.MD1_CombTableAdapter.FillBy1(Me.Mala2DataSet.MD1_Comb, vemp.ToString)
                If MsgBox("Please see similar existing names, want to continue?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.No Then
                    Exit Sub
                Else
            .........
                End If

                 .........
            Else
                ........

            End If
            DR.Close()
0
Comment
Question by:dovk179
[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
  • 2
4 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39611332
Assuming that empresa is a string, you need to pass single quotes around the vemp variable and wildcard %, like...

sSql = "select * from md1 where empresa like '" & vemp & "%'"

Open in new window

0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 500 total points
ID: 39611339
You missed the single quotes around the variable

sSql = "select * from md1 where empresa like '" & vemp & "%'"

When debugging these things, output the sSql string to the screen and then copy and paste it into SQL to test it.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39612626
dovk179 - Curiosity overwhelms me ... did you try my solution?
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39613542
Wow yeah. jimhorn kinda beat me to it by a few minutes. He should get the points, and to be honest the points should be a grade A as that solved your problem completely with example code.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 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