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
Rodolfo CalvoRodolfo Calvo 

How to make a simple SELECT <query> asp.net C#

How to make a simple SELECT from accounts module of an salesforce app module in asp.net C#.
How could be possible to make queries in asp.net MVC C# application and show them in a window of the app. 

Thanks! 
Best Answer chosen by Rodolfo Calvo
Rodolfo CalvoRodolfo Calvo
Here the answers didn't work either! :( it seems the programming level was too hardcore to ask. But I really appreciate too much! Thanks! 
 

All Answers

James LoghryJames Loghry
Rodolfo,

If you haven't already, please take a look at the Salesforce / .NET toolkit documentation here: https://developer.salesforce.com/page/Integrating_Force.com_with_Microsoft_.NET

A simple Account query would look like the following:
 
String SOQL = "Select Id from Account";
QueryResult queryResult = SfdcBinding.query(SOQL);
Rodolfo CalvoRodolfo Calvo
Making a simple SELECT in Asp.Net C#
I see, but there is a deeper issue with this. Let me explain, I made a MVC Asp.net C# app, I made the connection with salesforce but I need to show information [In this case taken from any module {Account}]. I got the customer id, secret serial number but the SELECT did not work. 
 
class Program
    {
        /// <summary>
        /// Strings connection for salesforce
        /// </summary>

        private static string _clientid = "Client123456789IDClient123456789IDClient123456789ID";
        private static string _clientSecret = "123456789123456";
        #region Username/passoword
        private static string _username = "myEmail@force.com";
        private static string _securityToken = "123456789123456";
        private static string _password = "myPassword" + _securityToken;
        #endregion
        private static string Agent = "salesforce-SDK-demo";
        private static string tokenRequest = "https://login.salesforce.com/services/oauth2/token";
    
        static void Main(string[] args)
        {
            var auth = new Salesforce.Common.AuthenticationClient();
            try {
                auth.UsernamePasswordAsync(_clientid, _clientSecret, _username, _password).Wait();
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            
            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
            Task<QueryResult<dynamic>> results = client.QueryAllAsync<dynamic>("SELECT id, FirstName, LastName, Email FROM Contact");
            results.Wait();
            var contacts = results.Result.Records;
            foreach (var contact in contacts)
            {
                Console.WriteLine(contact.FirstName);
            }

            Console.WriteLine("Press a key!");
            Console.Read();

        }
    }

This is what I did. When I debug it simply shows nothing. What am I doing wrong? 
Please help me with this. 
Thank you James. 
 
Rodolfo CalvoRodolfo Calvo
Here the answers didn't work either! :( it seems the programming level was too hardcore to ask. But I really appreciate too much! Thanks! 
 
This was selected as the best answer
Jay JanarthananJay Janarthanan
Take a look at the C# binding I have created for SF Rest API at https://github.com/jayonsoftware/apexsharp