Solved

SQL Statement in C#

Posted on 2006-07-06
7
197 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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