Showing posts with label OOP'S Concepts. Show all posts
Showing posts with label OOP'S Concepts. Show all posts

Thursday, 16 July 2015

Execute Stored Procedure with parameters and Fill Dataset

Introcution: Here you can call and execute stored procedure from code behind and pass the parameters and fill dataset.

Implementation:
DataSet ds = new DataSet();

            DataTable dt;

            sb.Append("<table>");

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {

                    using (SqlCommand command = new SqlCommand("sp_DistwiseDetails1", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;

                        command.Parameters.Add("@RetriveType", SqlDbType.VarChar).Value = 2;

                        command.Parameters.Add("@FromDate", SqlDbType.VarChar).Value = DateTime.Now.AddYears(-2);

                        command.Parameters.Add("@ToDate", SqlDbType.VarChar).Value = DateTime.Now.ToShortDateString();

                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                        {
                            adapter.Fill(ds);
                        }

                    }
                }
                dt = ds.Tables[0];
}
catch
{
}

Monday, 15 June 2015

Abstraction in OOPS C#

Abstraction: Abstraction is to hiding the complexity of object and showing the essential features of that object. It focus on what object can do instead of how it can do.
"Abstraction is to hiding the working style of an object and showing the information of an object as understandable manner"

Real world example of Abstraction:

Suppose we take example of Mobile phones.

Nokia 2710 (Features: Calling, SMS)
Nokia 3110 (Features: Calling, SMS, FM Radio, MP3, Camera)


Abstract information(All mobile phones makes a call to any number and can send SMS)

for that you have to make a abstract class:

abstract class MobilePhone
    {
        public void Calling();
        public void SendSMS();
    }

public class Nokia2710 : MobilePhone
    {
        public void FMRadio();
        public void MP3();
        public void Camera();
    }

    public class Nokia3110 : MobilePhone
    {
        public void FMRadio();
        public void MP3();
        public void Camera();
        public void Recording();
        public void ReadAndSendEmails();
    }