DataConnector
ADO.NET provider for Salesforce / Getting Started
In This Topic
    Getting Started
    In This Topic

    DataConnector offers everything from wide range of data connection techniques using ADO.NET provider for Salesforce. This documentation helps you get started with C1.DataConnector control which gives an idea about different ways of data connection and operations with Salesforce.

    This quick start will guide you through the steps of using DataConnector in a console application. Complete the steps given below to see how DataConnector works.

    Step 1: Create a new Console App

    1. Open Visual Studio
    2. Select File -> New -> Project.
    3. In the center pane, select Console App (.Net Core).
    4. Add a name for your app and select a location to save it.
    5. Click OK.
          Save app

    Step 2: Add the NuGet packages

    1. From the Project menu, select Manage NuGet Packages. The NuGet Package Manager appears.
    2. Select nuget.org from the Package source drop down.
    3. Click Browse tab and select C1.AdoNet.Salesforce from the left pane.
    4. In the right pane, click Install. This adds the references for the above packages.

    Step 3: Using ADO.Net provider for Salesforce

    Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for Salesforce.

    1.  The first step is to create a reference to Salesforce service URL.
         
      C#
      Copy Code
      const string GCSalesforceServerConnectionString = @"Username=*********;Password=*********;Security Token=***********;
                                                          OAuth Client Id=**************; 
                                                          OAuth Client Secret=*************; 
                                                          OAuth Token Endpoint=https://ap16.salesforce.com/services/oauth2/token; 
                                                          Url=https://ap16.salesforce.com/services/data/v45.0";
      
    2. In the next step, C1SalesforceDataAdapter is used to retrieve the data. C1SalesforceDataAdapter objects retrieve a single result set of all the data that matches a query. Click here for more information on creating connections.

      C1SalesforceConnection implements the ADO.NET DbConnection, similar to standard ADO.NET connection object. Once the connection is established, adapter's Fill method is used to retrieve the data from the source as shown in the below code example.
         
      C#
      Copy Code
      String sql = "SELECT Id,BillingCity,BillingState from [Order] limit 10";
      using (C1SalesforceConnection c = new C1SalesforceConnection($@"{GCSalesforceServerConnectionString}"))
      {
          //Open Connection
          c.Open();
          using (C1SalesforceDataAdapter a = new C1SalesforceDataAdapter(c, sql))
          {
              //Filling Data Table with the help of adapter
              DataTable t = new DataTable();
              a.Fill(t);
      
              //Printing the fetched table data on console
              foreach (DataRow dataRow in t.Rows)
              {
                  foreach (var item in dataRow.ItemArray)
                  {
                      Console.Write(item + " - ");
                  }
                  Console.WriteLine();
              }
          }
      }