473,387 Members | 1,502 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,387 software developers and data experts.

.NET error in query using LIKE expression

Hi,

Ive got the code working to an extent when comparing the searchterm with an column name, but there is still 2 problems Im having.

Initially the LIKE isnt working, Infact if I even enter nothing it brings up any record seeming to me that something is wrong somewhere, could this be the database (access xp???)

Secondly, reminding all those reading im a newbie, how do I apply concatenation as Ive been told this is what I need to use

Basically I want a drop down list which the user then selects the field to search i.e. nmno, pcsn etc. Then a 2nd box to type in a term to compare the contents to.

I.e. box 1.select ->Location. Box 2. type ward...........etc. Here my current semi-working query.

objCmd = new OleDbCommand("SELECT asset.*, pcdata.*"+

"FROM asset INNER JOIN pcdata ON asset.pcsn=pcdata.pcsn WHERE @seachtype LIKE @searchterm", objConn);

objCmd.Parameters.Add("@searchtype", ddlType.SelectedItem.Value);

objCmd.Parameters.Add("@searchterm", "%" + txtSearch.Text + "%");

I really appreciate all the help guys, If you can point me in the direction of a tutorial or something or maybe suggest what I may be im sure I can work it out.
Dec 12 '06 #1
2 1122
bplacker
121 100+
Hi,

Ive got the code working to an extent when comparing the searchterm with an column name, but there is still 2 problems Im having.

Initially the LIKE isnt working, Infact if I even enter nothing it brings up any record seeming to me that something is wrong somewhere, could this be the database (access xp???)

Secondly, reminding all those reading im a newbie, how do I apply concatenation as Ive been told this is what I need to use

Basically I want a drop down list which the user then selects the field to search i.e. nmno, pcsn etc. Then a 2nd box to type in a term to compare the contents to.

I.e. box 1.select ->Location. Box 2. type ward...........etc. Here my current semi-working query.

objCmd = new OleDbCommand("SELECT asset.*, pcdata.*"+

"FROM asset INNER JOIN pcdata ON asset.pcsn=pcdata.pcsn WHERE @seachtype LIKE @searchterm", objConn);

objCmd.Parameters.Add("@searchtype", ddlType.SelectedItem.Value);

objCmd.Parameters.Add("@searchterm", "%" + txtSearch.Text + "%");

I really appreciate all the help guys, If you can point me in the direction of a tutorial or something or maybe suggest what I may be im sure I can work it out.


concatenation is with &

and if you want to use like.. it should be similar to:
columnname like '%" & value & "%' "
Dec 12 '06 #2
sorry can you elaborate on your answer more please, I not sure I follow you, im new to C#. Where do i need to put in the & and also & val & ????
Dec 12 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
5
by: deko | last post by:
After developing an MDB in Access 2003 on WS03, then making it into an MDE and deploying it on a WinXP box with Access 2003 installed, I get this error: Function is not available in expressions...
2
by: stoppal | last post by:
I have the following query SELECT TOP 1 CDate(forms!frm_a!cbo_period & '/1/' & forms!frm_a!cbo_year) AS mydate, * FROM DBO_table WHERE DBO_table.field1=forms!frm_a!cbo_field1 And...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
1
by: amitbadgi | last post by:
I am geting the following error while conv an asp to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in query expression 'id =System.__ComObject'. Source...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
2
by: Tom Baxter | last post by:
I have a numeric column in a query called Prov1.Volume. When I try taking the sum of that column (using SUM aggregate function in Design View) it gives a syntax error. It says that...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
5
by: Just_a_fan | last post by:
I tried to put an "on error" statement in a routine and got the message that I cannot user "on error" and a lamda or query expression in the same routine. Help does not list anything useful for...
7
by: Yesurbius | last post by:
I am receiving the following error when attempting to run my query. In my mind - this error should not be happening - its a straight-forward query with a subquery. I am using Access 2003 with all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.