Friday 16 August 2013

Back in Hyderabad, The Hunt is going on......

After i had finished my internship in Inforica I went back to Nagpur for my project work and seminar work. Everything went of well and now i am back in Hyderabad. I came to Hyderabad last week to search for a job since i thought that there are better opportunities in Hyderabad. Let see what will happen. Hope for the best!!!

Sunday 2 June 2013

Last day of Internship











On the last day of our Internship we were feeling quit relaxed. Inforica is a great company, we had lots of new experiences everyday over here. Sudeep, our boss last month went Cannada for official work, so we got the Project completion Certificate from Shankar Sir.It was really good working with this company. Whatever we did, small tasks or Project work we have learn new things here. Today, I remember the first day when we came to office, we both were too nervous but excited at the same time. The last 4 months went here was really unforgettable. Will miss my desk, my chair, my friends over here and everything. I really want to thank Sudeep for giving me chance to do my Internship here. And as Sudeep said to work hard upon my programming skills, will surely follow his guidelines in future.

Thursday 9 May 2013

Query String Parameters

     Query String Parameters are used to pass values from one page to another page. Query String parameters are created by using the ? symbol at the end of the url while navigating to a page. Next to ? symbol, specify the parameter nae followed by = operator followed by the value to pass using that parameter. When you have multiple parameters then separate them with & symbol. 
          
                      Server.Transfer("~/page2.aspx?pname=value&pname=value")

To read Query String parameters, use query string property of Request object.

                      Varname=Request.QueryString["pname"]

The following example creates two pages Querystring1.aspx and Querystring2.aspx and withen the 1st page within a gridveiw the details of departments are displayed with select option and when user select a department then the selected deptno will be passed to 2nd page through querystring parameter and within the second page the list of employeees working in that deptnowill be displayed in a gridveiw.

1.  Add a page to the website with the name querystring1.aspx, take a gridview on it, set the id of that gridveiw to Gvdept, set its AutoGenerateSelectButton property to true

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace WebApp
{
    public partial class Querystring1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection("server=localhost; database=db1;uid=cheryl;trusted_connection=true");
            SqlCommand cmd = new SqlCommand("Select * from dept", cn);
            cn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            gvdept.DataSource = dr;
            gvdept.DataBind();
            gvdept.DataKeyNames = new string[] { "Deptno" };
            cn.Close();
            dr.Close();
        }
        protected void gvdept_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            gvdept.SelectedIndex = e.NewSelectedIndex;
            string Dno = gvdept.SelectedValue.ToString();
            Response.Redirect("~/Querystring2.Aspx?Dno=" + Dno);
        }
    }
} 
2.  Add another page to the website with the name querystring2.aspx. Place a gridveiw on that page, set its id as GvEmp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace WebApp
{
    public partial class Querystring2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Dno = Request.QueryString["Dno"].ToString();
            string Sql = "Select * from emp where Deptno=" + Dno;
            SqlConnection cn = new SqlConnection("server=localhost; database=db1;uid=cheryl;trusted_connection=true");
            SqlCommand cmd = new SqlCommand(Sql, cn);
            cn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            gvemp.DataSource = dr;
            gvemp.DataBind();
            cn.Close();
            dr.Close();

        }
    }
}

Wednesday 8 May 2013

LINQ to SQL (Example)

Example : Add a new form in project and design it as following.



Output :




Coding:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LinqProject1
{
   public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        CS11DBDataContext dc;
        List cust;
        int rno = 0;
        private void Form2_Load(object sender, EventArgs e)
        {
            dc = new CS11DBDataContext();
            cust = dc.GetTable().ToList();
            ShowData();
        }
        private void ShowData()
        {
            txtCustID.Text = cust[rno].CustId.ToString();
            txtCname.Text = cust[rno].Cname.ToString();
            txtCity.Text = cust[rno].City.ToString();
            txtBalance.Text = cust[rno].Balance.ToString();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (rno0)
            {
                rno -= 1;
                ShowData();
            }
            else
            {
                MessageBox.Show("First record of the table", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        } 
    } 
}

LINQ to SQL

Microsoft has provided LINQ as a lightweight facade that provides a strongly typed interface to the underlying data stores. LINQ provides the means for developers to stay within the coding environment they are used to and access the underlying data as objects that work with the IDE, intellisense, and even debugging. With LINQ the queries you create now become first-class citizens within the .Net framework alongside everything else you are used to. When you work with queries for the data store you are working with, you will quickly realize that they now work and behave as if they are types in the system.

LINQ to SQL in particular is a means to have a strongly typed interface against a SQL Server database. You will find the approach that LINQ to SQL provides is by far the easiest approach to the querying SQL Server available at the momoent. It is important to remember that LINQ to SQL is not only about querying data, but you also are able to perform Insert/Update/Delete statements that you need to perform which are known as CRUD operations (Create/Read/Update/Delete). Visual Studio comes into strong play with LINQ to SQL in that you will find an extensive user interface that allows you to design the LINQ to SQL classes you will work with.

Example : 

Place a DataGridView control on the first Form of project, change the name of DataGridView as gdView and write the following code:

Output:

 

Coding :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq;

namespace LinqProject1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CS11DBDataContext dc = new CS11DBDataContext();
            Table tab = dc.GetTable();
            dgview.DataSource = tab;
        }  
      
    }
}

Tuesday 7 May 2013

Collections

     Arrays are simple data structures used to store data items of a specific type Although commonly used, arrays have limited capabilities. For instance you must specify an array size, and if at execution time you wish to modify it you must do so by creating a new array or by using array classes resize method, which creates a new array and copies the existing elements into the new array.
     Collections are a set of prepackaged data structures that offer greater capability than traditional arrays. They are reusable, reliable, powerful and efficient and have been carefully designed and tested to ensure quality and performance. Collections are similar to arrays but provide additional functionalities, such as dynamic resizing - They automatically increase their size at execution time to accommodate additional elements, inserting of new elements, removing of existing elements etc.
     Initially .net introduces so many collection classes under the namespace System.Collections like Stack, Queue, LinkedList, SortedList, ArrayList etc.

Monday 6 May 2013

Query String Parameters

Query String parameters to pass values from one page to another page. Query string parameters are created by using ? symbol at the end of the url while navigating to a page. Next to the ? symbol, specify the parameter name followed by= operator  followed by the value to pass using that parameter. When, you have multiple parameters then seperate them with & symbol.

Server.Trnasfer("~/page2,aspx? pname=value& pname=value");

To read query string parameters, use QueryString property of Request object.

Varname=Request.QueryString["pname"];

Saturday 4 May 2013

Crystal Reports

         Crystal Reports is a business intelligence application used to design and generate reports from a wide range of data sources. Several other applications, such as Microsoft Visual Studio bundle and OEM version of Crystal Reports as a general purpose reporting tool. Crystal Reports become the de facto standard report writer when Microsoft released it with Visual Studio.
       The product was originally created by crystal services Inc. as Quik reports when they could  not find a suitable commercial report writer for their accounting software. After producing versions 1.0 through 3.0, the company was acquired in 1994 by Seagate Technology. Crystal Services was combined with Holostic Systems to form the information group of Seagate software, which later rebranded as crystal decisions, and produced versions 4.0 through 9.0. Crystal decisions was acquired in December 2003 by business objects, which has so far produced versions 10, 11 and current version 12.
         

Wednesday 1 May 2013

Session State Management

Session is a block of memory on server allocated separately for every user of the website and is used to store the data that is private to a particular user. For the applications like online shopping session state is required for storing items selected by the user in different pages and finally gets the list of session and prepares the bill

Session has the following advantages over Cookies
  • Session data is stored on server and then there will be security for the data. But cookies are stored on client system in plain text file and hence there is no security for the data.
  • Session can store any type of data whereas a cookie can store only standard type of data like int,float,double,string,date.
  • Session has no limit and you can store any type of data in the session whereas a cookie can store a maximum of only 4KB data and overall 80KB if the browser allows a maximum of 20 cookies per website.
  • Session state cant be disabled by an end user and hence the code within using session will work whereas cookies can b disables with end user in browser and hence there is no guarantee that your code that uses cookies will work.

Tuesday 30 April 2013

State Management

Web and HTTP protocol are stateless. Hence server cant identify whether or not two requests came from same user and server will treat every request as the request from a new user. Because of the stateless nature of the web it is not possible to develop applications like shopping cart and implementing security in the websites. To overcome this problem, Asp.Net provides state management techniques. Client Side State Management techniques include Cookies, Viewstate and QueryString Parameters and Server side state management techniques include Session, Application and Caching.

 COOKIES

A cookie is a small amount of memory allocated on client system for storing personnel information about the client like remembering user id and password, making a count of failed login attempts, security and also session state management. To create a cookie use HttpCookie class and to assign a value to the cookie use its Value property and finally to store it in a client system call AppendCookie() method of Response object.

Sunday 28 April 2013

Extensible Markup language (XML).

         XML Stands for Extensible Markup Language. Its a language much like HTML which was designed to carry data, not to display data and also self-descriptive. XML does not do anything. XML was created to structure,store and transport information. XML tags are not predefined, you must define your own tags. XML is not a replacement for HTML, HTML and XML were designed with different goals:
  • XML was designed to transport and store data, with focus on what data is.
  • HTML was designed to display data, with focus on how data looks.
  • HTML is about displaying information, while XML is about carrying information.
To create an XML document we need to satisfy a set of rules that are prescribed by W3C, as following
  • An XML doc has to be saved with .xml extention.
  • Data under XML doc should be present only under tags, where every tag should have a start and end element.       eg:   <Tag><Tag> Or <Tag id="1"/>
  • Tags can also be defined with attribute which are user-defined where value to attribute should be enclosed under double quotes.
  • While defining tags start and end tag should match in case.
  • An Xml doc can only have one root element.

Friday 26 April 2013

Accessing MS Excel data from .Net Application

Ms Excel is a file system which stores data in the form of rows and columns same as a database table. An Excel document is referred as Work Book that contains Work Sheets in it, work books are considered as databases and work sheets are considered as tables.First row of work sheet can store column names.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace WinForms7
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }
        OdbcConnection con; OdbcCommand cmd; OdbcDataReader dr; string Sqlstr;
        private void Form6_Load(object sender, EventArgs e)
        {
            con = new OdbcConnection("Dsn=ExcelDsn; ReadOnly=0");
            cmd = new OdbcCommand();
            cmd.Connection = con;
            con.Open();
            LoadData();
            label1.Text = dr.GetName(0); label2.Text = dr.GetName(1);
            label3.Text = dr.GetName(2); label4.Text = dr.GetName(3);
               
        }
        private void LoadData()
        {
            cmd.CommandText = "Select * from[Student$]";
            cmd.ExecuteReader();
            ShowData();


        }
        private void ShowData()
        {
            if (dr.Read())
            {
                textBox1.Text = dr[0].ToString();
                textBox2.Text = dr[1].ToString();
                textBox3.Text = dr[2].ToString();
                textBox4.Text = dr[3].ToString();
            }
            else
                MessageBox.Show("No data exists");

               
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = " ";
            textBox1.Focus();
        }
        private void ExecuteDML()
        {
            dr.Close();
            cmd.CommandText = Sqlstr;
            if (cmd.ExecuteNonQuery() > 0)
                MessageBox.Show("Insert or Update operation was successful");
            else
                MessageBox.Show("Insert or Update operation failed");

                LoadData();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Sqlstr = String.Format("Insert into [Stident$] values({0},'{1}' {2},{3})", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
            dr.Close();
            ExecuteDML();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Sqlstr = String.Format("Update [Stident$] Set Sname='{0},Class={1}, Fees= {2} where Sno={3}", textBox2.Text, textBox2.Text, textBox3.Text, textBox4.Text);
            dr.Close();
            ExecuteDML();
        }
    }
}

Thursday 25 April 2013

DataList, Repeater and FormView and Details View Controls

Today, I practiced some examples using Data List Control, Repeater and FormView Controls in Asp.Net.
 
DataList Control: 

Datalist control is similar to gridview except that it has no predefined layout and hence it can be designed in any layput you want, which is not possible with gridview because it has predefined table layout. It doesn't support paging and sorting wheareas gridview supports paging and sorting.

Repeater:

Repeater control can display multiple rows to gridiew and datalist. But unlike gridview and datalist the data in repeater is readonly.Similar to datalist it has no predefined layout and you can design it with any layout. As repeater is readonly, it has very limited set of properties, methods and events and hence it is very light weight and provides fast access, it has the important properties DatasourceId and Datasource. It has only one important event ItemCommand that will be raised when user click on any button within the repeater.

Wednesday 24 April 2013

GridVeiw

GridVeiw control is one of the data controls provided in ASP.net that can display Multiple rows at a time. GridVeiwhas a predefined table layout that displays the data in the table format. Gridveiw supports update, delete and sorting but it does not suppoort insert. Gridveiw also supports paging using which we can divide rows of the grid veiw into pages.

Properties
  • AllowPaging
  • PagerSettings
  • PageSize
  • PageIndex
  • AllowSorting
  • EnableSortingAndPagingCallbacks
  • AytoGenerateColumns
  • AutoGenerateDeleteButton
  • AutoGenerateEditButton
  • AutoGenerateSelectButton
  • Columns
  • DataKeyName
  • SelectedIndex
  • SelectedValue
  • DataSource
  • DataSourceID
  • EditIndex
  • EmptyDataText
  • HeaderRow
  • FooterRow
  • Rows
  • ShowHeader
  • ShoeFooter
Events
  • SelectedIndexChanging
  •  PageIndexChanging
  • RowEditing
  • RowUpdating
  • RowCancelingEdit
  • RowDeleting
  • Sorting

Tuesday 23 April 2013

Image Map

Image Map is used to divide the image into different hotspots and allow the user to navigate to different pages by clicking on different hotspot or execute different code when user clicks on different hotspot or execute different code when user clicks on different hotspot based on the hotspot on which user clicked. It has thee property image URL to specify the image to display within the ImageMap and the property hotspots to specify different hotspots required within the image map.

Three different types of hotspots you can create within the Imagemap and they are circle hotspot, rectangle hotspot and polygon hotspot. The rectangle hotspot has the properties bottom,left, right and top to specify position and size of the rectangle hotspot and circle hotspot has the properties radius x and y to specify the radius and center point of the circle and polygon hotspot and circle hotspot has the property co ordinates to specify the points using which you want to draw the polygon.

All the types of hotspots have the following three properties :-
  • Hotspot Mode:-  Used to specify the mode of hotspot and it has the options like not set, inactive, navigate and postback.
  • Navigate Url:- Used to specify Url of the page to navigate when hotspot mode is set to navigate and user click on the hotspot.
  • Target :- When Hotspot Mode is set to navigate then this property is used to specify the target when to display the navigate URL.
 

Monday 22 April 2013

Ad Rotator Control

Ad Rotator is used to display advertisements on the page and change the advertisement with every request. Ad rotator support displaying the advertisement from an XML file and also from the database.

Properties:
  • Advertisement File: When you want to display advertisements in the ad rotator from a XML file then this property is used to specify URL of the XML file from which to take the details of advertisements.
  • Alternate Text Field: Used to specify column name in table that contains alternate tex for the advertisements.
  • ImageUrlField: Used to specify column name in the table that contain Url of the image to display for the advertisements.
  • Navigate Url Field: Used to specify the column name in table that contains Url of the page to display when user clicks on the advertisements.
  • DataSource: Used to specify ID of a data source control to use as a data source for the ad rotator.
  • KeywordFilter:Used to specify a keyword based on which advertisements displayed in the ad rotator will be filtered.

Calender Control

Calender is used to display calender to the user on the page and allow the user to select a date or a range of  dates.

Properties:
  • DateNameFormat : Used to specify the format in which the week name is displayed within the calender.
  • FirstDayofWeek:Used to specify week name in which you want to start the calender.
  • SelectedDate: Used to specify the date selected within the calender.
  • Selection Mode: Used to specify whether user can select a single date or day and week or day, week and month.
Events:
  • SelectionChanged: This is the default event for the calender and it eill be raised whenever a new date is selected in the calender.
  • DayRender: This event will be raised once for every day rendered in the calender.

DataGridVeiw Control

This control is used to display the data in the form of a table i.e. rows and columns. To display data in the control first we need to bind the DataTable of DataSet to the GridVeiw control by using a DataSource property as following
                  dataGridVeiw1.DataSource=<datatable>

DataGridVeiw control has a specialty ie changes performed to data in it gets reflected directly to the data of DataTable to which it was bound, so that we can update dataset back to database directly.

To test this add a new form in the project and place a DataGridVeiw control on it setting the dock property as top. Now place 2 buttons on the form setting the text as save and close


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace WindowsFormsApp
{
    public partial class Form9 : Form
    {
        public Form9()
        {
            InitializeComponent();
        }
        SqlConnection con;
        SqlDataAdapter da;
        SqlCommandBuilder cb;
        DataSet ds;
        private void Form9_Load(object sender, EventArgs e)
        {
            string constr = ConfigurationManager.ConnectionStrings["SConstr"].ConnectionString;
            con = new SqlConnection(constr);
            ds = new DataSet();
            da = new SqlDataAdapter("Select Eno,Ename,Job,Salary From Employee Order By Eno", con);
            da.Fill(ds, "Employee");
            dataGridView1.DataSource = ds.Tables[0];

        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            cb = new SqlCommandBuilder(da);
            da.Update(ds, "Employee");
            MessageBox.Show("Data saved to db sarver");
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

Thursday 18 April 2013

Add a new form in the project and design it as following






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
namespace WindowsFormsApp
{
    public partial class Form7 : Form
    {
        SqlConnection con;
        SqlCommandBuilder cb;
        DataSet ds;
        int rno = 0;
        SqlDataAdapter da;

        public Form7()
        {
            InitializeComponent();
        }

        private void Form7_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("server=localhost; database=db1;uid=cheryl;trusted_connection=true");
            da = new SqlDataAdapter("Select Eno,Ename,Job,Salary from Employee Order By Eno", con);
            ds = new DataSet();
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            da.Fill(ds, "Employee");
            ShowData();
        }
        public void ShowData()
        {
            txteno.Text = ds.Tables[0].Rows[rno][0].ToString();
            txtname.Text = ds.Tables[0].Rows[rno][1].ToString();
            txtjob.Text = ds.Tables[0].Rows[rno][2].ToString();
            txtsalary.Text = ds.Tables[0].Rows[rno][3].ToString();
        }

        private void btnfirst_Click(object sender, EventArgs e)
        {
            rno = 0;
            ShowData();
        }

        private void btnprev_Click(object sender, EventArgs e)
        {
            if (rno > 0)
            {
                rno -= 1; ;
                if (ds.Tables[0].Rows[rno].RowState == DataRowState.Deleted)
                {
                    MessageBox.Show("Deleted row cannot be accessed.");
                    return;
                }
                ShowData();
            }
            else MessageBox.Show("First record of table");
        }

        private void btnnext_Click(object sender, EventArgs e)
        {
            if (rno 0)
            {
                int Eno = int.Parse(value);
                DataRow dr = ds.Tables[0].Rows.Find(Eno);
                if (dr != null)
                {

                    txteno.Text = dr[0].ToString();
                    txtname.Text = dr[1].ToString();
                    txtjob.Text = dr[2].ToString();
                    txtsalary.Text = dr[3].ToString();
                }
                else
                {
                    MessageBox.Show("Employee doesnot exist for a given employee no.");
                }
            }

        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();

        }
    }
}

Wednesday 17 April 2013

Configuration files

While developing applications if there are any values in application which requires changes in future, should not be hard coded i.e. should not be maintained as static values within the application, because if any changes are required to those values in future client will not be able to make those changes because they will not have the source code for modification. To overcome this problem we need to identify those values and put them under a special file known as configuration file, its an XML file which stores values in it in the form of key/value pairs. The values that are present under configuration files can be read from applications in runtime. When an application is installed on a client machines along with it its configuration file will also be installed there and because the configuration file is a text file clients can edit those files and make modifications to the values under them at any time and those values will be taken into the application for execution.

Tuesday 16 April 2013

Connecting .net application with Sql Server


We can connect with Sql Server from .net applications either by using Oledb or SqlClient class.

Add a new form in the project and design it as follows :-


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApp
{
    public partial class Form6 : Form
    {
        SqlCommand cmd;
        SqlConnection con;
        SqlDataReader dr;
        string SqlStr;
        public Form6()
        {
            InitializeComponent();
        }

        private void Form6_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("server=localhost; database=db1;uid=cheryl;trusted_connection=true");
            cmd = new SqlCommand();
            cmd.Connection = con;
            con.Open();
            LoadData();
        }
       public void LoadData()
       {
           cmd.CommandText="Select sid,sname,course from stud Order By sid ";
           dr = cmd.ExecuteReader();
           ShowData();
       }
        public void ShowData()
        {
            if (!dr.IsClosed && dr.Read())
            {
                txtid.Text = dr[0].ToString();
                txtname.Text =dr[1].ToString();
                txtcourse.Text = dr[2].ToString();
            }
            else
                MessageBox.Show("No data exists");
        }

        private void btnnext_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void btnnew_Click(object sender, EventArgs e)
        {
            txtid.Text = txtname.Text = txtcourse.Text = "";
            dr.Close(); 
            cmd.CommandText = "Select IsNull(Max(sid),1000)+1 from stud";
            txtid.Text = cmd.ExecuteScalar().ToString();
            btninsert.Enabled = true;
            txtname.Focus();
        }
        private void ExecuteDML()
        {
            DialogResult d = MessageBox.Show("Are you sure of executing the above SQL statement?\n\n" + SqlStr, "Comfirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (d == DialogResult.Yes)
            {
                cmd.CommandText = SqlStr;
                int count = cmd.ExecuteNonQuery();
                if (count > 0)
                    MessageBox.Show("Statement executed successfully");
                else
                    MessageBox.Show("Statement failed execution");
            }
        }

        private void btninsert_Click(object sender, EventArgs e)
        {
            SqlStr = "Insert into Stud(sname,course) values ('" + txtname.Text + "','" + txtcourse.Text + "')";
            ExecuteDML();
            btninsert.Enabled = false;
        }

        private void btnupdate_Click(object sender, EventArgs e)
        {
            SqlStr = "Update Stud set sname ='"+ txtname.Text + "', course = '" + txtcourse.Text + "' Where sid="+txtid.Text;
            dr.Close();
            ExecuteDML();

        }

        private void btndelete_Click(object sender, EventArgs e)
        {
            SqlStr = "Delete From Stud where sid=" + txtid.Text;
            dr.Close();
            ExecuteDML();

        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            if (con.State != ConnectionState.Closed)
            {
                con.Close();

            }
            this.Close();

        }
    }
}