You need to sign in to do that
Don't have an account?
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
Hi alivepjc,
First, there is lots of sample syntax in the documentation, but mostly you should base your query on standard SQL syntax and look for variations in SOQL.
The reason why you are not having success with the non-hardcoded version is that your user is not entering single quotes with the name of the account. Or maybe you don't want them to enter the single quotes. If that is the case, then change your query line to
qr = binding.query("select Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry from Account where Name = '" + accName + "'");Cheers