Solved

SQL Statement in C#

Posted on 2006-07-06
7
196 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
  • 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 20 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET (2008) - Refactoring Question 2 21
Cant save 3D 4 21
C# Gridview 1 33
How come this regular expression allows "e"? 14 38
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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