Monday, 29 April 2013

3-Tire Architecture Example
































.aspx
<body>
<form id="form1" runat="server">
    <fieldset id="Field1" runat="server">
    <legend>Employee</legend>
    <center>
<table>
   
<tr>
<td>Ename:</td>
<td><asp:TextBox ID="txtename" runat="server"></asp:TextBox></td>
</tr>
<tr><td>Designation</td>
    <td><asp:TextBox ID="txtDesignation" runat="server"></asp:TextBox></td>
</tr>
<tr><td>Location</td>
    <td><asp:TextBox ID="txtlocation" runat="server"></asp:TextBox></td>
</tr>
<tr><td colspan="2" class="style1">
    <asp:Button ID="btnsubmit" runat="server" Text="Submit"
            onclick="btnsubmit_Click" />
            &nbsp;<asp:Label ID="lblmessage" runat="server" Text="[lblMsg]" Visible="False">
    </asp:Label>
    </td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="gdv" runat="server" AutoGenerateColumns="false">
<Columns>
    <asp:BoundField HeaderText="Ename" DataField="ename" />
    <asp:BoundField HeaderText="Designation" DataField="Designation" />
    <asp:BoundField HeaderText="Location" DataField="Location" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</center>
</fieldset>
</form>
</body>

Helper Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace SqlHelper
{
    public class Helper
    {
        //Sql connection
        SqlConnection conn;
        public int insert(string query)
        {
            string connect = ConfigurationManager.ConnectionStrings["Sqlcon"].ToString();
            conn = new SqlConnection(connect);
            SqlCommand com = new SqlCommand(query, conn);
            //Connection Open
            conn.Open();
            int x = com.ExecuteNonQuery();
            //Connection Close
            conn.Close();
            return x;
        }
        public DataSet load(string querry)
        {
            string connect = ConfigurationManager.ConnectionStrings["Sqlcon"].ToString();
            conn = new SqlConnection(connect);
            SqlDataAdapter da = new SqlDataAdapter(querry, conn);
            DataSet ds=new DataSet();
            da.Fill(ds);
            return ds;
        }



    }
}


Business Object layer(BOL)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessObjectLayer
{
    public class BOL
    {
        public BOL()
        {
        }
        string ename=string.Empty;
        string designation = string.Empty;
        string location = string.Empty;


        public string Ename
        {
            get { return ename; }
            set { ename = value; }
        }
        public string Designation
        {
            get { return designation; }
            set { designation = value; }
        }
        public string Location
        {
            get { return location; }
            set { location = value; }
        }
    }
}

Business Access layer(BAL)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessObjectLayer;
using SqlHelper;

namespace BusinessAccessLayer
{
    public class BAL
    {
        public int insertvalue(BOL objBOL)
        {
            Helper Objhelper = new Helper();
            string query = "Insert Into  dsp values('"
objBOL.Ename + "','"+objBOL.Designation+"','"+objBOL.Location+"')";
            return Objhelper.insert(query);
        }
        public object loadvalues()
        {
            Helper Objhelper = new Helper();
            string querry = "select *from dsp";
            return Objhelper.load(querry);
}
}
}

Friday, 29 March 2013


Microsoft .Net Type Conversions

Conversion is based on type compatibility and data compatibility.

There are two types of conversions:

1.  Implicit Conversion
2.  Explicit Conversion

Implicit Conversion

In implicit conversion the compiler will make conversion for us without asking.

char -> int -> float is an example of data compatibility.

Complier checks for type compatibility at compilation


class Program
    {
        static void Main(string[] args)
        {
            int num1 =20000;
            int num2 =50000;
            long total;
// In this the int values are implicitly converted to long data type;
//you need not to tell compiler to do the conversion, it automatically does.
            total = num1 + num2;

            Console.WriteLine("Total is : " + total);
            Console.ReadLine();
        }
    }

Below table shows the implicitly type conversions that are supported by C#:
  
From
To
sbyte
short, int, long, float, double, decimal
byte
short, ushort, int, uint, long, ulong, float, double, decimal
short
int, long, float, double, decimal
ushort
int, uint, long, ulong, float, double, decimal
int
long, float, double, decimal
uint
long, ulong, float, double, decimal
long
float, double, decimal
ulong
float, double, decimal
float
double
char
ushort, int, uint, long, ulong, float, double, decimal

Explicit Conversion

In explicit conversion we specifically ask the compiler to convert the value into another data type.

CLR checks for data compatibility at runtime.

Explicit conversion is carried out using casts. When we cast one type to another, we deliberately force the compiler to make the transformation.

You should never expect that the cast would give you best or correct result. Casts are potentially unsafe. Casting of big data type into small may lead to loosing of data.

 class Program
    {
        static void Main(string[] args)
        {
            int num = 65;
  char alpha;
            alpha = (char)num;
// In this the int values are explicitly converted to char data type.
//you have to tell compiler to do the conversion, it uses casting.
           
            Console.WriteLine("alphabet is: " + alpha);
            Console.ReadLine();
        }
    }
Microsoft .NET provides three ways of type conversion:
1.  Parsing
2.  Convert Class
3.  Explicit Cast Operator ()

Parsing

Parsing is used to convert string type data to primitive value type. For this we use parse methods with value types.

Practical demonstration of parsing

using System;
namespace parsing
{
    class Program
    {
        static void Main(string[] args)
        {
            //using parsing

            int number;
            float weight;

            Console.Write("Enter any number : ");
            number = int.Parse(Console.ReadLine());

            Console.Write("Enter your weight : ");
            weight = float.Parse(Console.ReadLine());

            Console.WriteLine("You have entered : " + number);
            Console.WriteLine("You weight is : " + weight);

            Console.ReadLine();
        }
    }
}

Convert Class


One primitive type to another primitive type.
This class contains different static methods like ToInt32(), ToInt16(), ToString(), ToDateTime() etc used in type conversion.
 Practical demonstration of Convert class
 using System;

namespace convert_conversion
{
    class Program
    {
        static void Main(string[] args)
        {
            // example of using convert class

            string num = "23";
            int number = Convert.ToInt32(num);

            int age = 24;
            string vote = Convert.ToString(age);

            Console.WriteLine("Your number is : " + number);
            Console.WriteLine("Your voting age is : " + age);

            Console.ReadLine();
        }
    }
}

Explicit Cast Operator ()
In general this operator is used with non-primitive types to up level or down level casting. But it can also used with any type having type compatibility and data type compatibility.
using System;

namespace explicit_cast_conversion
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2;
            float avg;
            num1 = 10;
            num2 = 21;
            avg = (float)(num1 + num2) / 2;

            Console.WriteLine("average is : " + avg);
            Console.ReadLine();
        }
    }
}

SharePoint tenant opt-out for modern lists is retiring in 2019

We're making some changes to how environments can opt out of modern lists in SharePoint. Starting April 1, 2019, we're going to be...