function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
alivepjcalivepjc 

Filtered query problem .net C#

Hi,

I am having problems filtering my queries in C# .net. I downloaded the sample code, but I can't make them work.

I am trying to retreive 1 account based on its name.

If I hard code the Name field which is my filter, it works, if I pass a variable, it doesn't.

////////////////////////////////

private static void doGetAccounts()

{

//check to see if we are already logged in

if (lr == null)

{

Console.WriteLine("Run the login sample before the others.\n");

getUserInput("Hit enter to continue: ");

Console.WriteLine("\n");

return;

}

//create a variable to hold the query result

sforce.QueryResult qr = null;


// get user input for account name

String accName = getUserInput("Please enter the account name: ");

//call the query saving the results in qr

try

{

// non-working query

qr = binding.query("select Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry from Account where Name = " + accName);

// working query

qr = binding.query("select Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry from Account where Name = 'Chris'");

}

catch (Exception e)

{

Console.WriteLine(e.Message + "\n" + e.StackTrace);

return;

}

//////////////////////////

please help me out!. Sample queries would be awesome!

thank you,

chris

SuperfellSuperfell
try

qr = binding.query("select Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry from Account where Name = '" + accName + "'");