Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Statement in C#

Posted on 2006-07-06
7
Medium Priority
?
202 Views
Last Modified: 2010-04-16
Hi

Im trying this but it gives me 0 results.

string pcname = "\\pc024";
                populateListBox(listBoxProcessesOnSelectedMachine, "SELECT processtype FROM processes WHERE processname = '" + pcname + "'", false);

               

I try this in SQL SERVER and it gives me three results

SELECT     processtype
FROM         processes
WHERE     processname = '\\pc024'

Am I missing something blatant?
Thanks

0
Comment
Question by:hmcgeehan
[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
  • 3
7 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17050603
change this

string pcname = "\\pc024";

to this

string pcname = @"\\pc024";
0
 
LVL 23

Expert Comment

by:apresto
ID: 17050607
by using @ you are telling the string to act as is, if you use \\, this is in terpretted as \ without the @
0
 

Author Comment

by:hmcgeehan
ID: 17051282
Thanks

Just another small question

I have a listbox and its contents are

\\pc001
\\pc002

etc

but if I do

pcname = listBox1.SelectedItem.ToString();

it says

pcname = \\\\pc001
0
 
LVL 23

Accepted Solution

by:
apresto earned 80 total points
ID: 17051661
this will be interpreted as \\pc001

you need 2 \ to represent 1 \ unless you use @ before it:

i.e

\\pc1 = \pc1
\\\\pc1 = \\pc1
\\\\\\pc1 = \\\pc1

@"\pc1" = \pc1
@"\\pc1" = \\pc1
@"\\\pc1" = \\\pc1
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

609 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