Solved

error 102

Posted on 2013-10-30
4
290 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
  • 2
  • 2
4 Comments
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
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
Comment Utility
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 65

Expert Comment

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

Expert Comment

by:Lee Savidge
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

12 Experts available now in Live!

Get 1:1 Help Now