Link to home
Start Free TrialLog in
Avatar of hmcgeehan
hmcgeehan

asked on

SQL Statement in C#

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

Avatar of apresto
apresto
Flag of Italy image

change this

string pcname = "\\pc024";

to this

string pcname = @"\\pc024";
by using @ you are telling the string to act as is, if you use \\, this is in terpretted as \ without the @
Avatar of hmcgeehan
hmcgeehan

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of apresto
apresto
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial