SQL in .NET question

How do i use the LIKE and the wildcards in a search in .NET (using c#)

example in straight SQL:


if i try and use it in .NET like follows:


I get an error.
10/2/2003 12:54:51 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 12
Get it on Google Play
Get it on Apple App Store



and then prepend and append '%' characters to the string you are passing in.
Starting with ASP.NET 2.0? Look at:
Programming Microsoft Web Forms
My Blog
10/2/2003 2:37:07 PM
Wow, I didn't know you could do that.

I usually do this which works as well (no prepending of '%' to the variable):
SELECT * FROM myDB WHERE LastName LIKE '%' + @MyVar + '%'

Terri Morton
Engagement Manager, Neudesic

How to ask a question

10/2/2003 9:35:18 PM
::I usually do this which works as well (no prepending of '%' to the variable): 

::SELECT * FROM myDB WHERE LastName LIKE '%' + @MyVar + '%'
VERY bad :-)
I normally use (when I do SQL manipulation like this):
string parameter = "%"+myvar+"%";
String.Format ("SELECT * FROM myDB WHERE LastName LIKE {0}", parameter);
A litle more readable. Naturally you ahve to be CAREFULL like hell about SQL insertsions, which is why all parameters go through a formatting routine of their own :-)

Thomas Tomiczek
PowerNodes ApS
(Microsoft MVP C#/.NET)
Building a Website? Try the PowerNodes CMS - http://www.powernodes.com/
10/3/2003 11:17:34 AM

Similar Artilces:

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

To .NET or not .NET, that is the question
I'm running WinXP pro 32-bit, meaning I've got the version 1-dot-something of .NET that XP came with. I've been looking for various softwares, and more and more often come across .NET version 2 being prerequisite. No urgency for me re. my questions to this group - so far I have just decided to hit the red X on those download pages - but the desire for this newer version of .NET seems to be growing for me. Firstly, according to my (limited) research, newer .NET versions are inclusive of the previous ones, and the current version seems to be 3.5. So if I go for i...

sql insert .net question
Hello, wrote an insert for a C#.Net web app. The insert works fine, except if there are appostrophies (spelling) for example: this isn't a problem this isnt a problem the second one will work the first will not. The info is going into a sql server database as text(16), the same result occurs with char. I believe you'll need to use an escape character "\", so something like this: "this isn\'t a problem" Also, you should try to use stored procedures or at the very least paramater queries. Both of those would solve your problem as well."I would l...

DW.NET support for SQL Anywhere .NET provider
Hello, we are trying to get DW.NET (v. 2.5) working with Sybase SQL Anywhere .NET provider for database access. Does anybody know if that is possible, and if so, then how? The reason for this question is that we are evaluating DW.NET as a solution for document printing from our existing C# application which uses SQL Anywhere .NET provider. I would expect that these two products should work together, as they are both developed by Sybase and targeted for the same .NET platform. Linas ...

Strange difference between SQL from .Net and SQL within stored proc
Hi, I am trying to fill a DataGrid with random records from my database. It thought I had found a way to randomly select records using SQL. So I built a stored procedure in Access and sure enough, it returns a random set of records. Whe I tried to call this from my app, it kept returning the same set of records. So I copied and pasted the SQL into the app (code below) but it made no difference. Could anyone tell me why this wouldn't work? <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="...

T-SQL TRIGGER causes crash in .Net, Interactive SQL works...?
Hi All I am fairly new to Sybase databases. I have a database with a single table (AdressenStorage) to that table I added (T-SQL)triggers for INSERT, UPDATE and DELETE. Everything works fine with InteractiveSQL. But as soon as I execute the statements from my .Net application, it crashes. (The program hangs at cmd.ExecuteNonQuery() ). I removed all triggers and everything worked fine. Right now I have just the (reduced) INSERT trigger (which still crashes): CREATE TRIGGER "AdressenStorage_Insert" on DBA.AdressenStorage for insert as begin -- Handle RevIsCurrent ...

Attach SQL DB to SQL Server 2005 using VB.Net
Is there any way to attach a SQL DB to SQL Server 2005 using VB.Net?  If so can you also set security? Can you rephrase your question? Attach SQL DB from which version of SQL server ? Look up books online for sp_attachdb and sp_detachdb.***********************Dinakar NethiLife is short. Enjoy it.*********************** I have a DB that was created in SQL Server 2005.  I have a website that displays data from systems all over the world.  Each system sends it's data to it's own DB.  The customer can then go to a website and see the data at real time.  What ...

Sql Server Script File(.sql) Execution by Vb.net Code
I have a problem. I m working on "light weight sql server"  project.   and i want to execute .sql file through vb.net code with the help of sqldmo library and sqlns namespace. but i donot know any method to directly execute the .sql file. i am successfully making the full script of select database of sql server.   please help me.... thanks.... Hi, You can use SQL-DMO object in your .net projects by referencing Sqldmo.dll  file which is in  C:\Program Files\Microsoft SQL Server\80\Tools\Binn  folder is default installation parameters are used. I...

sql anywhere 10 .NET provider & sql anywhere 8 server
sql anywhere 10 .NET provider & sql anywhere 8 server are there any major known issues other than test for my scenarios or it is not compatible at all. i was able to connect, add, delete & update records on a simple table & dataset. Env: VS 2005 .NET 2.0 & sql anywhere 10 thanks vsv This configuration should work. But we do not do significant (if any) testing of this configuration, so you should ensure you do thorough testing with your application. -- Ian McHardy (iAnywhere Solutions) Please reply only to the newsgroup. Whitepapers, TechDo...

creating ssis packagte for sql server to sql serer using C#.net
Hi friendsdoes any one has code or urls which can help me to create the ssis pacakage which will transfer data from sql server to sql server databaseswith some manipulationsthanks so much Lad LaxmikantPune You are probably in the wrong forum.  This forum is for questions relating to ASP.NET Dynamic Data. thanks,David...

Interview Questions on C#, SQL & .NET OOPs
Hi Guys I've compiled some notes & Interview Questions on C#, SQL & .NET OOPs... If interested you may read them at http://moredotnet.googlepages.com Cheers!       Vishal Khanna.NET Interviews & FAQs @ www.dotnetUncle.comClick Mark as Answer if the reply helped you. As someone who does a lot of interviewing, it's always a pleasure to see posts like these, as it gives me a chance to refine my questions to make them much harder. However, in this case, I'm a little less worried because the incompleteness of the answers (and some of them are just plain w...

SQL Server 05 & .NET .dll's: executing .dll from T-SQL
Can I manually execute a .dll stored in SQL Server 2005?Is it possible for this .dll to do anything: call a Web Service, process XML, etc?Thanks. ...

.Net 2 web app and Reporting Services (both SQL 2000 and SQL 2005)... Can it be done?
My setup:.Net 2 web app running in [localhost] with AJAX extensions.  2 virtual web folders Reports and ReportServer for Reporting Services in SQL 2000.  I understand that RS (Reporting Services) for SQL 2000 only runs in .Net Framework 1.1, so I have set both Reports and ReportServer to run in a different application pool [ASP.NET 1.1] and set their .net Framework to 1.1.  But when I try to load a report through our app or try to load the Reports folder it reports and error in the web.config of our web app in localhost.  The error in the web.config is something specific ...

I cannot stop Visual Studio.NET 2005 from looking for SQL Server 2005 instead of SQL 2000
I would like to know how to set SQL2000 as the default database server when running any webapplication. I have installed Visual Studio.NET and SQL Server 2000 locally in my laptop.  But anytime I want to run a webapplication I am getting the following error:System.Data.SqlClient.SqlException was unhandled by user code  Class=20  ErrorCode=-2146232060  LineNumber=0  Message="An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server doe...

Web resources about - SQL in .NET question - asp.net.sql-datasource

German question - Wikipedia, the free encyclopedia
"Kleindeutschland" redirects here. For the neighborhood in New York City, see Little Germany, Manhattan . 1820 map of Central Europe showing ...

Melbourne Victory's Kevin Muscat irked by questions of Roy O'Donovan's ban
The famous Muscat stare was in evidence midway through his pre-match chat with journalists after Victory's training session on Thursday.

Question Of The Day: Worst Craigslist nightmare?
Filed under: Etc. , Used Car Buying Buyers that demand a lifetime warranty. Sellers who lie. Flakes who don't show up. What's your worst car-related ...

iPhone 6s demand called into question as Apple reportedly orders cut back in production
Citing sources familiar with Apple's supply chain, Nikkei is reporting that the company is scaling back iPhone 6s and 6s Plus production by as ...

One SAHM's Answer to the Dreaded Question: 'Do You Work?'
We volunteer at school (but not too much). We get involved with sports (but not too much). We show up at every poetry reading, tipi-making event, ...

'Making a Murderer' lawyers answer 2 burning questions viewers have about the Steven Avery case
Steve Avery's defense attorney Dean Strang and former Calumet County prosecutor Ken Kratz appeared on Fox News to address questions about the ...

Question #5 for 2016: Will the Fed raise rates in 2016, and if so, by how much?
Earlier I posted some questions for next year: Ten Economic Questions for 2016 . I'll try to add some thoughts, and maybe some predictions for ...

Bill Clinton Avoids Reporter’s Question About Reemergence Of Juanita Broaddrick
Bill Clinton Avoids Reporter’s Question About Reemergence Of Juanita Broaddrick

Podtoid records today, ask us questions!
Here's a little peek behind the curtain: there's a good chance you don't listen to Podtoids on Wednesday, unless that's the soonest day post ...

EXCLUSIVE: Saint West Is 'Definitely' Kim Kardashian's Last Pregnancy, But Adoption Isn't Out of the ...
Doctors have told Kim Kardashian that it's too risky for her to conceive again, a source close to Kim tells ET.

Resources last updated: 1/8/2016 9:55:36 AM