Dot Net

Code to show message box
write this code on button click

{
MessageBox.Show("You are strictly warned for doing this!!!","Warning message",MessageBoxButtons.OKCancel ,MessageBoxIcon.Hand);
}

Before doing this you have to add the component of system.windows.form


Below code is helpful to get the count of days, after u enter from and to dates on respected textboxes

       DateTime dFrom;  
       DateTime dTo;  
        string sDateFrom = Textbox1.text;  
        string sDateTo = Textbox2.text;  
        if (DateTime.TryParse(sDateFrom, out dFrom) && DateTime.TryParse(sDateTo, out dTo))  
        {  
            TimeSpan TS = dTo - dFrom;  
            int daysDiff = TS.Days;  
            txtDateDiff.text=daysDiff.ToString();  
        }


Code to Check the Existing Record simply avoiding duplicate record



protected void Button1_Click(object sender, EventArgs e)
    {
        if (checkifexist(TextBox6.Text))
        {
            Label14.Text = "Record already exists";
        }
        else
        {
            string at = "insert into register values('" + TextBox6.Text + "','" + TextBox1.Text + "','" + TextBox2.Text 


+ "','" + TextBox3.Text + "','" + DropDownList1.Text + "','" + DropDownList2.Text + "','" + TextBox4.Text + "','" 


+ DropDownList3.Text + "','" + TextBox5.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "')";
            SqlCommand cmd = new SqlCommand(at, con);
            con.Open();
            cmd.ExecuteNonQuery();
            Label14.Text = "Record Inserted Successfully";
            con.Close();
        }
    }


    protected bool checkifexist(string Emp_id)
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
        string a = "select * from register where Emp_id='" + TextBox6.Text + "'";
        SqlCommand cmdr = new SqlCommand(a,con);
        SqlDataAdapter ad = new SqlDataAdapter(cmdr);
        DataTable dt = new DataTable();
        ad.Fill(dt);


       if(dt.Rows.Count>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }


Following code is completely helpful to you to design a Login Page, Read Values and more



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Windows.Forms;


public partial class Default2 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("server=.;uid=sa;database=employee_timesheet");
    protected void Page_Load(object sender, EventArgs e)
    {
        //Label2.Enabled = false;
        //TextBox1.Enabled = false;
    }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList3.SelectedValue != "Fresher")
        {
            
            Label20.Visible = true;
            Label14.Visible = true;
            Label15.Visible = true;
            Label16.Visible = true;
            Label17.Visible = true;
            TextBox9.Visible = true;
            TextBox10.Visible = true;
            TextBox11.Visible = true;
            TextBox12.Visible = true;
        }
        else
        {
            Label20.Visible = false;
            Label14.Visible = false;
            Label15.Visible = false;
            Label16.Visible = false;
            Label17.Visible = false;
            TextBox9.Visible = false;
            TextBox10.Visible = false;
            TextBox11.Visible = false;
            TextBox12.Visible = false;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Calendar1.Visible = true;
        TextBox4.Text = Calendar1.SelectedDate.Date.ToString();
        Calendar1.Visible = false;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Transgender")
        {
            Label26.Visible = true;
        }
        else
        {
           Label26.Visible = false;
         
        }

    }


    protected void Button2_Click(object sender, EventArgs e)
    {       
        labeltextvisible();
        Label2.Visible = false;
        Button2.Enabled = false;
          
    }
    

   protected void Button3_Click(object sender, EventArgs e)
    {
        Label2.Visible = true;
        TextBox1.Visible = true;
        Button3.Text = "View Record";
        Label2.Enabled  = true  ;
        TextBox1.Enabled  = true  ;


        if (TextBox1.Text == "")
        {
            MessageBox.Show("Please Type Employee ID to get Employee's Record");
        }
        else
        {
            con.Open();
            Label2.Enabled = false ;
            TextBox1.Enabled = false ;
            SqlDataReader dr;
            string a1="Select ename,efname,gender,dob,qlf,maritalstatus,bgroup,paddress,caddress,email,mobile,jobposition,dateofjoining,prnsal,expnce,previouscomname,sal,reason_forleaving,pre_position from empdetails where empid='"+TextBox1.Text+"'";
            SqlCommand cmd = new SqlCommand(a1, con);
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                TextBox2.Text = dr["ename"].ToString();
                TextBox3.Text = dr["efname"].ToString();
                TextBox4.Text = dr["dob"].ToString();
                //DropDownList3.Text = dr["dob"].ToString();
                TextBox15.Text = dr["qlf"].ToString();
                //DropDownList4.Text = dr["maritalstatus"].ToString();
                TextBox16.Text = dr["bgroup"].ToString();
                TextBox5.Text = dr["paddress"].ToString();
                TextBox6.Text = dr["caddress"].ToString();
                TextBox13.Text = dr["email"].ToString();
                TextBox14.Text = dr["mobile"].ToString();
                //DropDownList2.Text = dr["jobposition"].ToString();
                TextBox7.Text = dr["dateofjoining"].ToString();
                TextBox8.Text = dr["prnsal"].ToString();
                //DropDownList3.Text = dr["expnce"].ToString();
                TextBox9.Text = dr["previouscomname"].ToString();
                TextBox10.Text = dr["sal"].ToString();
                TextBox11.Text = dr["reason_forleaving"].ToString();
                TextBox12.Text = dr["pre_position"].ToString();
            }
            dr.Close();   
            con.Close();
            
            Button3.Text = "Update";
           /* string a2 = "update empdetails set(ename='" + TextBox2.Text + "',efname='" + TextBox3.Text + "',gender='" + DropDownList1.Text + "',dob='" + TextBox4.Text + "',qlf='" + TextBox15.Text + "',maritalstatus='" + DropDownList4.Text + "',bgroup='" + TextBox16.Text + "',paddress='" + TextBox5.Text + "',caddress='" + TextBox6.Text + "',email='" + TextBox13.Text + "',mobile='" + TextBox14.Text + "',jobposition='" + DropDownList2.Text + "',dateofjoining='" + TextBox7.Text + "',prnsal='" + TextBox8.Text + "',expnce='" + DropDownList3.Text + "',previouscomname='" + TextBox9.Text + "',sal='" + TextBox10.Text + "',reason_forleaving='" + TextBox11.Text + "',pre_position='" + TextBox12.Text + "' where empid='" + TextBox1.Text + "')";
            con.Open();
            SqlCommand cmd1 = new SqlCommand(a2, con);
            cmd1.ExecuteNonQuery();
            MessageBox.Show("Employees Record Updated Successfully on our Database");
            con.Close();*/
        }
        
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Label2.Visible = true;
        TextBox1.Visible = true;
        if (TextBox1.Text == "")
        {
            MessageBox.Show("Please Type Employee ID to Delete Employee's Record");
        }
        else
        {
            con.Open();
            string a = "delete from empdetails  where empid='" + TextBox1.Text + "'";
            SqlCommand cmd = new SqlCommand(a, con);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Employees Record Deleted Successfully from the Database");
            con.Close();
            TextBox1.Text = "";
            TextBox1.Focus();
        }
    }


    private void labeltextvisible()
    {
        Label1.Visible = true;
        Label2.Visible = true;
        Label3.Visible = true;
        Label4.Visible = true;
        Label5.Visible = true;
        Label10.Visible = true;
        Label8.Visible = true;
        Label7.Visible = true;
        Label6.Visible = true;
        Label11.Visible = true;
        Label12.Visible = true;
        Label13.Visible = true;
        Label14.Visible = true;
        Label15.Visible = true;
        Label20.Visible = true;
        Label16.Visible = true;
        Label17.Visible = true;
        DropDownList1.Visible = true;
        DropDownList2.Visible = true;
        DropDownList3.Visible = true;
        TextBox2.Visible = true;
        TextBox3.Visible = true;
        TextBox4.Visible = true;
        TextBox5.Visible = true;
        TextBox6.Visible = true;
        TextBox7.Visible = true;
        TextBox8.Visible = true;
        TextBox9.Visible = true;
        TextBox10.Visible = true;
        TextBox11.Visible = true;
        TextBox12.Visible = true;
    }


    private void labeltextvisiblefalse()
    {
        Label1.Visible = false ;
        Label2.Visible = false ;
        Label3.Visible = false ;
        Label4.Visible = false ;
        Label5.Visible = false ;
        Label10.Visible = false ;
        Label8.Visible = false ;
        Label7.Visible = false ;
        Label6.Visible = false ;
        Label11.Visible = false ;
        Label12.Visible = false ;
        Label13.Visible = false ;
        Label14.Visible = false ;
        Label15.Visible = false ;
        Label20.Visible = false ;
        Label16.Visible = false ;
        Label17.Visible = false ;
        DropDownList1.Visible = false ;
        DropDownList2.Visible = false ;
        DropDownList3.Visible = false ;
        TextBox2.Visible = false ;
        TextBox3.Visible = false ;
        TextBox4.Visible = false ;
        TextBox5.Visible = false ;
        TextBox6.Visible = false ;
        TextBox7.Visible = false ;
        TextBox8.Visible = false ;
        TextBox9.Visible = false ;
        TextBox10.Visible = false ;
        TextBox11.Visible = false ;
        TextBox12.Visible = false ;
    }


    protected void Button5_Click(object sender, EventArgs e)
    {
       
        if (TextBox2.Text == "")
        {
            MessageBox.Show("Please Fill all essential Details before click Insert");
        }
        else
        {
            con.Open();
            string a = "insert into empdetails values('" + TextBox2.Text + "','" + TextBox3.Text + "','" + DropDownList1.Text + "','" + TextBox4.Text + "','" + TextBox15.Text + "','" + DropDownList4.Text + "','" + TextBox16.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox13.Text + "','" + TextBox14.Text + "','" + DropDownList2.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + DropDownList3.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "','" + TextBox12.Text + "')";
            SqlCommand cmd = new SqlCommand(a, con);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Employees Record Successfully Stored on our Database");
            con.Close();
        }
        //labeltextvisiblefalse();
    }
}