• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Creating Business Data Connectivity Service-Visual Studio 2010

New Create Database name BCSForSharePoint2010

  • Create a new table name: Customer with the following columns:
  • Enter new customer data

86

Open Visual Studio 2010 to create a new BCS

  • File | New Project | SharePoint | 2010 | Select Data Connectivity Business Model and name BCSCustomer
  • Select Site and click Finish to Debugging

Interface creates the following new

 

87

 

Rename the Class Entity1 CustomerEntity

88

Rename the primary key of CustomerID from Identifier1

89

 

In the Properties window of the CustomerID, Name Type: select System.Int32

90

BDC Explorer window

Expand Model | Expand BdcModel1 | Expand CustomerEntity | Expand ReadItem | Expand id and choose Identifier

91

Rename the primary key of CustomerID from Identifier1

 

92

 

-In the Properties window of the CustomerID, Name Type: select System.Int32

 

93

-Selected the following image

94

 

Expand Model | Expand BdcModel1 | Expand CustomerEntity | Expand ReadItem | Expand returnParameter and select Entity1

95

-Change from the Customer Entity1

96

 

-In the customer select the CustomerID and choose Identifier1 Name Type: select System.Int32

97

-Renamed CustomerName, Type Name: System.String

98

 

-Click to Customer | Add Type Descriptor

99

-Named the City, the Type Name: System.String

1

-Expand Model | Expand BdcModel1 | Expand CustomerEntity | Expand ReadList | Expand returnParameter and select  Entity1List

2
-CustomerList changed

3

 

-Expand Model | Expand BdcModel1 | Expand CustomerEntity | Expand ReadList | Expand returnParameter | Expand  CustomerList | Choose Entity1

4

 

Customer changed

5

-Expand Customer | Change Identifier1 the CustomerID

6

-In the Properties window of the CustomerID, Name Type: select System.Int32

7

 

-Select Message and renamed CustomerName, Type Name: System.String

8

 

-Click to Customer | Add Type Descriptor

9

-Named the City, the Type Name: System.String

10

 

Solution Explorer window | Select Class Entity1

11

 

 

  • Renamed Customer
  • Declare the following codepublic partial class Customer
    {
    / / TODO: Implement Additional properties here.
    / / The Message property is just a sample how a property could look like.
    public int CustomerID {get; set;}
    public string CustomerName {get; set;}
    public string City {get; set;}
    }

Method Details window BDC – CustomerEntity | collap ReadItem method, ReadList

Click the Add method in the combobox and select the Create Delete Method Member

12

At TekSlate, we offer resources that help you in learning various IT courses. 
We avail both written material and demo video tutorials. 
To gain in-depth knowledge and be on par with  practical experience, then explore SharePoint Training Course.

Interface as follows

13

• Double click on the file and found ReadItem method appears CustomerEntityService.cs
• Using the following declaration code

 

using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;

• Declare the SqlConnection method returns the name GetSqlConnection

 

GetSqlConnection static SqlConnection ()
{
string ConnectionString = “server = (local) database = BCSForSharePoint2010; Integrated Security = true”;
SqlConn SqlConnection = new SqlConnection (ConnectionString);
sqlConn return;
}

• In the alternative method ReadItem error code with the following code:

public static ReadItem Customer (int id)
{
Customer customer = new Customer ();
SqlConn = GetSqlConnection SqlConnection ();
sqlConn.Open ();
SqlCommand SqlCommand = new SqlCommand ();
sqlCommand.CommandText = “select CustomerID, CustomerName, City”
+ “From Customer”
+ “WHERE CustomerID =” + id.ToString ();
sqlCommand.Connection = sqlConn;
SqlDataReader SqlDataReader = sqlCommand.ExecuteReader(CommandBehavior. CloseConnection);
if (sqlDataReader.Read ())
{
customer.CustomerID = int. Parse (SqlDataReader [0]. ToString ());
customer.CustomerName = SqlDataReader [1]. ToString ();
Customer.City = SqlDataReader [2]. ToString ();
}
else
{
customer.CustomerID = -1;
customer.CustomerName = “Customer Not Found”;
Customer.City = “”;
}
sqlConn.Dispose ();
return customer;
}

• In the method declaration code ReadList

/ / / <summary>
/ / / This is a sample method for Entity1 finder.
/ / / If You Want to delete or rename the method to think about changing the xml file in the BDC model as well.
/ / / </ Summary>
/ / / <returns> IEnumerable of Entities </ returns>
public static IEnumerable <Customer> ReadList ()
{
SqlConnection SqlConnection = GetSqlConnection ();
try
{
List <Customer> allCustomers = new List <Customer> ();
sqlConnection.Open ();
SqlCommand SqlCommand = new SqlCommand ();
sqlCommand.Connection = SqlConnection;
sqlCommand.CommandText = “select CustomerID, CustomerName, City from Customer”;
SqlDataReader SqlDataReader = sqlCommand.ExecuteReader (CommandBehavior. CloseConnection);
while (sqlDataReader.Read ())
{
Customer customer = new Customer ();
customer.CustomerID = int. Parse (SqlDataReader [0]. ToString ());
customer.CustomerName = SqlDataReader [1]. ToString ();
Customer.City = SqlDataReader [2]. ToString ();
allCustomers.Add (customer);
}
Customer [] = new Customer customerList [allCustomers.Count];
for (int customerCounter = 0; customerCounter <= allCustomers.Count – 1; customerCounter + +)
{
customerList [customerCounter] = allCustomers [customerCounter];
}
return (customerList);
}
catch (Exception ex)
{
Tellme String = ex.Message;
Customer [] customerlist = new Customer [0];
Customer customer = new Customer ();
customer.CustomerID = -1;
customer.CustomerName = “Unable to retrieve data”;
Customer.City = “”;
customerlist [0] = customer;
return (customerlist);
}
finally
{
sqlConnection.Dispose ();
}
}
• In the Delete method declaration code

public static void Delete (int CustomerID)
{
SqlConnection SqlConnection = GetSqlConnection ();
sqlConnection.Open ();
SqlCommand SqlCommand = new SqlCommand ();
sqlCommand.Connection = SqlConnection;
sqlCommand.CommandText = “delete customer WHERE CustomerID =” + customerID.ToString ();
sqlCommand.ExecuteNonQuery ();
sqlConnection.Dispose ();
}

 

After completion code hi build and Deploy project

14

Open Central Administration | Application Management | Manage service selected applications
You choose to Business Data Connectivity Service
You check CustomerEntity BCSCustomer.BdcModel1 with namespace and select Icon Set Object Permissions
Add your user rights for that user and select

15

 

Open the site with the port as was at first Debugging ( http://acer:8888 ) and select All Site Content

Choose Create

Data at the category | select External List | select Create

BCSCustomer named below and select the icon to add External Content Type

Choose BdcModel1 with External Content Type and select OK BCSCustomer.BdcModel1.CustomerEntity

For Indepth understanding of SharePoint click on

Summary
Review Date
Reviewed Item
Creating Business Data Connectivity Service-Visual Studio 2010
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Creating Business Data Connectivity Service-Visual Studio 2010"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.