Introduction to SharePoint Web Part


Refer the following link

Life Cycle

The methods are called in the following order.

OnInit – Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part. Initialize the values here.
LoadViewState – The view state of the web part is populated over here. (When its a post back)
CreateChildControls – All the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() – It checks to see if the CreateChildControls method has been called and if not it would call it.
User Generated Event – for e.g. button click on the web part.
OnPreRender – Here we can change any of the web part properties before the control output is drawn.
RenderContents – Html Output is generated.
SaveViewState – View state of the web part is serialized and saved.

SQL CE with ASP .NET Application

Use the below code snippet to make SQL CE it work with ASP .NET application
protected void Page_Load(object sender, EventArgs e)
AppDomain.CurrentDomain.SetData(“SQLServerCompactEditionUnderWebHosting”, true);
string connectionString = @”Data Source=|DataDirectory|\Northwind.sdf”;
Northwind nw = new Northwind(connectionString);
var DataSource = nw.Orders.Skip(0).Take(100).Select(o => o);
<add assembly=”System.Data.SqlServerCe, Version=, Culture=neutral, PublicKeyToken=89845DCD8080CC91″&gt
</assemblies &gt

SQL CE db creation with C#

I hope this would be useful for porting a MDF Sql db to CE Sql db.
we all very much familiar with ADO.NET the namespaces available for SQL server data provider are System.Data and System.Data.SqlClient similarly in ADOCE.NET for SQL CE data provider are System.Data and System.Data.SqlserverCE. The process to develop an application to use SQL Server CE is
  • Check for database available or not if not create the database through SqlCeEngine object as below

    (!File.Exists(\\My Documents\\EmpDB.sdf))
    SqlCeEngine empEngine = new
    SqlCeEngine(“Data Source = \\My Documents\\EmpDB.sdf”);

    Note : the database file name must have .sdf extension

  • After create the database is created next step is to create the required tables

    SqlCeConnection empCon;
    SqlCeCommand empCom;
    empCon =
    new SqlCeConnection(“Data Source = \\My Documents\\EmpDB.sdf”);
    empCom = empCon.CreateCommand();
    strQuery = “CREATE TABLE Employee (EmpID int IDENTITY(0,1) PRIMARY KEY,EmpName nvarchar(10),Salary int)”;

    This code snippet create a table with three columns ( empid,emp name & salary )

  • Once you setup the database then further operations are store or fetch data , ii can be done through SqlCeDataReader as below

    string strQuery = “SELECT * FROM Employee ORDER By EmpName ASC”;
    empCom.CommandText = strQuery;
    SqlCeDataReader empReader = empCom.ExecuteReader();

you can use the code and fill the datas from the existing MDF to CE.