473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Wildcard "%" not working

MB
Hi,
I am using a datagrid and the datagrid is filled through the SQL
query. The SQL query searches for the match in the database. The SQL
Query that i am writing is as follows

Dim selprod As String = "SELECT ProductID, ProductName FROM Products
WHERE ProductName LIKE '%prod%'"

but it is not working.
If I use the query this way(as given below) it works but I want to use
wildcard so that it searches thoroughly and provide with me with all
the records

Dim selprod As String = "SELECT ProductID, ProductName FROM Products
WHERE ProductName LIKE '" + prod + "'"

If i use LIKE '" +%prod%+ "'" or something sort of like this it doesnt
work either... any idea how it will work.

P.S My database is in SQL Server

Thanks in advance
MB
Nov 20 '05 #1
2 1972
Hi,

Dim strConn As String
Dim conn As SqlConnection

strConn = "Server = (local);"
strConn += "Database = NorthWind;"
strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

Dim cmd As SqlCommand
Dim strProduct As String = "chef"
Dim strSQL As String
strSQL = String.Format("Select * from Products Where Productname
LIKE '%{0}%'", strProduct)
cmd = New SqlCommand(strSQL, conn)

conn.Open()
Dim dr As SqlDataReader
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read
Console.WriteLine(dr.Item("productname"))
Loop
End Sub

Ken
----------------------
"MB" <ma******@yahoo.com> wrote in message
news:13**************************@posting.google.c om...
Hi,
I am using a datagrid and the datagrid is filled through the SQL
query. The SQL query searches for the match in the database. The SQL
Query that i am writing is as follows

Dim selprod As String = "SELECT ProductID, ProductName FROM Products
WHERE ProductName LIKE '%prod%'"

but it is not working.
If I use the query this way(as given below) it works but I want to use
wildcard so that it searches thoroughly and provide with me with all
the records

Dim selprod As String = "SELECT ProductID, ProductName FROM Products
WHERE ProductName LIKE '" + prod + "'"

If i use LIKE '" +%prod%+ "'" or something sort of like this it doesnt
work either... any idea how it will work.

P.S My database is in SQL Server

Thanks in advance
MB

Nov 20 '05 #2
* ma******@yahoo.com (MB) scripsit:
I am using a datagrid and the datagrid is filled through the SQL
query. The SQL query searches for the match in the database. The SQL
Query that i am writing is as follows

Dim selprod As String = "SELECT ProductID, ProductName FROM Products
WHERE ProductName LIKE '%prod%'"

but it is not working.
If I use the query this way(as given below) it works but I want to use
wildcard so that it searches thoroughly and provide with me with all
the records

Dim selprod As String = "SELECT ProductID, ProductName FROM Products
WHERE ProductName LIKE '" + prod + "'"

If i use LIKE '" +%prod%+ "'" or something sort of like this it doesnt
work either... any idea how it will work.


Your question is 0 percent related to VB.NET. Please post to the
appropriate group in future:

<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.adonet>

Thank you for your cooperation!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: ST | last post by:
Hi, I'm new to vb.net programming, and I keep getting this error: Name 'GetQuery' is not declared. I can't figure out why?? It seems like I have the right references/namespaces. This is my code...
2
by: Dave Smithz | last post by:
Hello there, Summary: How far can you go with SQL Select queries using like clauses with wildcard characters. Can you apply anything like regular expressions? Full details: On a Intranet...
2
by: deko | last post by:
I'm trying to use a textbox to search and display records as each letter is typed in - similar to the behavior of a combo box. But for some reason I can't seem to get the wildcard search character...
9
by: Paweł | last post by:
Hello! I'm looking for efficient code or site where I can find code for finding one string in another string. String which I search should have "wild" characters like '?' for any one char and...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment (to learn enough ASP/VB.net to port a series of ...
11
by: Bruce Lawrence | last post by:
Ok, I'm baffled... I'm making a query in access 97 between 2 tables. There is a field in both tables called "DWGNO". OPENORD has a record with a DWGNO of "00000012345" DIEDATA has a record...
1
by: Lucvdv | last post by:
In my assembly.vb files, I'm using the revision/build wildcard style: <Assembly: AssemblyVersion("3.0.*")> <Assembly: AssemblyFileVersion("3.0.*")> This onkly seems to work in projects that...
7
by: BlackJack17 | last post by:
I have another newbie question for you guys... I apologize in advance for how simple it is... I've got a string of data, included in that string is 11* as it appears, the * is not a wildcard. ...
3
by: deve8ore | last post by:
Hello, I have built a macro to automatically go to a specific directory and a specific folder, however the names of the files I need to automatically locate change names every month. I.e. - I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.