Solved

SQL Statement in C#

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now