Introduction to SharePoint Web Part

Creation

Refer the following link

http://www.c-sharpcorner.com/UploadFile/shivprasadk/12222301222009065151AM/122223.aspx

http://msdn.microsoft.com/en-us/library/ms452873.aspx

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.
OnLoad
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.
Dispose
UnLoad

SQL CE with ASP .NET Application

Use the below code snippet to make SQL CE it work with ASP .NET application
[C#]
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);
}
[WebConfig]
<assemblies&gt
<add assembly=”System.Data.SqlServerCe, Version=3.5.1.0, 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

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

    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”);
    empCon.Open();
    empCom = empCon.CreateCommand();
    string
    strQuery = “CREATE TABLE Employee (EmpID int IDENTITY(0,1) PRIMARY KEY,EmpName nvarchar(10),Salary int)”;
    empCom.CommandText=strQuery;
    empCom.ExecuteNonQuery();

    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.