?
Solved

SQL Statement in C#

Posted on 2006-07-06
7
Medium Priority
?
204 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
4 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

831 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