Wednesday, October 14, 2015

Insert_Update_delete_Using_Grid_View_Using_One_Procedure_Connection_in__Web.Config



.................................DataBase........................................


create database ranjeet_db
...................................................
drop table employee
---------------------------------------------------
create table employee
(
id int primary key,
FirstName varchar(50),
MName varchar(50),
LastName varchar(50)

)

------------------------------------------------------
select * from employee


------------------------------------------------------
 -----------Procedure---------------------------------
------------------------------------------------------

 create Procedure EmpEntry
(
  --variable  declareations
 @Action Varchar (10),    --to perform operation according to string ed to this varible such as Insert,update,delete,select     
 @id int=null,    --id to perform specific task
 @Fname Varchar (50)=null,   -- for FirstName
 @MName Varchar (50)=null,   -- for MName
 @Lname Varchar (50)=null    -- for LastName
)
as
Begin
  SET NOCOUNT ON;

If @Action='Insert'   --used to insert records
Begin
   Insert Into employee (FirstName,MName,LastName)values(@Fname,@MName,@Lname)
End


else if @Action='Select'   --used to Select records
Begin
    select *from employee
end


else if @Action='Update'  --used to update records
Begin
   update employee set FirstName=@Fname,MName=@MName,LastName=@Lname where id=@id
 End


 Else If @Action='delete'  --used to delete records
 Begin
   delete from employee where id=@id
 end





 End

------------------------------------------------------------------------------------------------



....................................................Default.aspx.....................................................

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


    <h4>This Application is Created by Ranjeet Kumar</h4>
     <table>
    <tr>
    <td>First Name</td>
<td>
   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>   
  
        </td>   
    </tr>
   
     <tr>
    <td>Middle Name</td>

<td>
   <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>        
 
          </td>
         </tr>

      <tr>  
    <td>Last Name</td>
<td>
   <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>        
 
          </td>   
    </tr>
    <tr>
    <td>
        <asp:Button ID="Button1" runat="server" Text="Save" onclick="empsave" />
    </td>
    </tr>
    </table>
    <asp:label ID="Label1" runat="server" text="Label"></asp:label>
   
   
    <asp:HiddenField ID="HiddenField1" runat="server" />
   
   
    <asp:GridView ID="GridView1" runat="server"  DataKeyNames="id" OnRowEditing="edit"
        OnRowCancelingEdit="canceledit"
        OnRowDeleting="delete"
        OnRowUpdating="update"
       
         CellPadding="4" ForeColor="#333333"
        GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataSourceID="SqlDataSource1">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:CommandField ShowDeleteButton="True" />
        </Columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>
   
   
 </asp:Content>

.............................................................Web.config For DB Connection...............................

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>

  <connectionStrings>
    <add name="RK_CON" connectionString ="Data Source=RANJEETKUMAR-PC\SQLEXPRESS;Initial Catalog=ranjeet_db;User Id=sa;Password=ranjeet"
         providerName ="System.Data.SqlClient"/>

  </connectionStrings>
 
 
 
</configuration>




..................................................(c#)Default.aspx.cs............................................................


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;//import it sql connection
using System.Configuration;// import it web.config connection
using System.Data;//import it for CommandType


public partial class _Default : System.Web.UI.Page
{

    string query;
    SqlConnection con;
    SqlCommand com;

    public void connection()
    {

      string  constr = ConfigurationManager.ConnectionStrings["RK_CON"].ToString();

      
        con = new SqlConnection(constr);
        con.Open();
    }



    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack == false)
        {
           gedata();


        }
        Label1.Visible = false;
    }
    protected void empsave(object sender, EventArgs e)
    {
        connection();
        HiddenField1.Value = "Insert";
        query = "EmpEntry";
        com = new SqlCommand(query, con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.AddWithValue("@Action", HiddenField1.Value).ToString();
        com.Parameters.AddWithValue("@FName", TextBox1.Text).ToString();
        com.Parameters.AddWithValue("@MName", TextBox2.Text).ToString();
        com.Parameters.AddWithValue("@LName", TextBox3.Text).ToString();

        int result = com.ExecuteNonQuery();
     
        con.Close();
      
        if (result >= 1)
        {
            Label1.Text = "Records Are Added";

        }

    }

    public void gedata()
    {
        connection();
        HiddenField1.Value = "view";
        query = "EmpEntry";
        com = new SqlCommand(query, con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.AddWithValue("@Action", HiddenField1.Value).ToString();
        SqlDataAdapter da = new SqlDataAdapter(com);
        DataSet ds = new DataSet();
        da.Fill(ds);
       
      //GridView1.DataSource = ds;

   
  
   // GridView1.DataBind();
        con.Close();

    }




    protected void edit(object sender, GridViewEditEventArgs e)
    {

        GridView1.EditIndex = e.NewEditIndex;
        gedata();
    }
    protected void canceledit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        gedata();
    }
    protected void update(object sender, GridViewUpdateEventArgs e)
    {
        connection();

        int id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());//here taking gridview id
      
        HiddenField1.Value = "update";
        query = "EmpEntry";
        com = new SqlCommand(query, con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.AddWithValue("@Action", HiddenField1.Value).ToString();
        com.Parameters.AddWithValue("@FName", ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString());
        com.Parameters.AddWithValue("@MName", ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString());
        com.Parameters.AddWithValue("@LName", ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text.ToString());
        com.Parameters.AddWithValue("@id", SqlDbType.Int).Value = id;
        com.ExecuteNonQuery();
        con.Close();
        GridView1.EditIndex = -1;
        gedata();
    }
    protected void delete(object sender, GridViewDeleteEventArgs e)
    {
        connection();
      
        int id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());//here taking gridview id
      
        HiddenField1.Value = "Delete";
        query = "EmpEntry";
        com = new SqlCommand(query, con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.AddWithValue("@Action", HiddenField1.Value).ToString();
        com.Parameters.AddWithValue("id", SqlDbType.Int).Value = id;
        com.ExecuteNonQuery();
        con.Close();
        gedata();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

Registration And Login Coding In ASP.Net

   ...................................Database......................

create database ranjeet_db
create table reg
(
id int,
name varchar(50),
pass varchar(24)
)

insert into reg values('1','ranjeet','1')
select * from reg



...............................Register.aspx.......................................................................

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

   
    <asp:Table ID="Table1" runat="server">
        <asp:TableHeaderRow>
        </asp:TableHeaderRow>

        <asp:TableRow>

            <asp:TableCell>Emp Id</asp:TableCell><asp:TableCell>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:TableCell>
        </asp:TableRow>

        <asp:TableRow>

            <asp:TableCell>Name</asp:TableCell><asp:TableCell>
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:TableCell>
        </asp:TableRow>

        <asp:TableRow>

            <asp:TableCell>Password</asp:TableCell><asp:TableCell>
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></asp:TableCell>
        </asp:TableRow>

        <asp:TableRow>
         <asp:TableCell></asp:TableCell>
        </asp:TableRow>
       
         

    </asp:Table>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <asp:Label runat="server" ID="error" Text="Label"></asp:Label>
</asp:Content>

 


..................................C# coding (Register.aspx.cs)..................................................... 

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;

public partial class _Default : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection("Data Source=RANJEETKUMAR-PC\\SQLEXPRESS; Initial Catalog=ranjeet_db; User Id=sa; Password=ranjeet");
     
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //con.Open();
        //if (con.State.ToString() == "Open")
        //{
        //    error.Text = "open Connection";
        //}

        try
        {


           string str = "insert into reg values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"') ";
          
            


                //string str = "insert into [reg] (id,name,pass) values(@id,@name,@password)";
               
                 SqlCommand cmd = new SqlCommand(str, con);

                //cmd.Parameters.Add(new SqlParameter("@id", (object)TextBox1.Text));
                //cmd.Parameters.Add(new SqlParameter("@name", (object)TextBox2.Text));
                //cmd.Parameters.Add(new SqlParameter("@password", (object)TextBox3.Text));

            


                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                error.Text = "Sucessfuly Inserted";
               
            }
            catch(Exception ex)
            {
                error.Text = "Error "+ex;
            }
      
    }
}






....................................................Login.aspx..........................................
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

     <asp:Table ID="Table1" runat="server">
        <asp:TableHeaderRow>
        </asp:TableHeaderRow>

        <asp:TableRow>

            <asp:TableCell>Emp Id</asp:TableCell><asp:TableCell>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:TableCell>
        </asp:TableRow>

           <asp:TableRow>

            <asp:TableCell>Password</asp:TableCell><asp:TableCell>
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></asp:TableCell>
        </asp:TableRow>

        <asp:TableRow>
         <asp:TableCell><asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></asp:TableCell>
        </asp:TableRow>
       
         




    </asp:Table>
   
    <asp:Label runat="server" ID="error" Text="Label"></asp:Label>
</asp:Content>

.........................................C#(Login.aspx.cs).............................

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;

public partial class Login : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=RANJEETKUMAR-PC\\SQLEXPRESS; Initial Catalog=ranjeet_db; User Id=sa; Password=ranjeet");
     
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {


            string str = " select * from reg where id='"+TextBox1.Text+"' AND pass='"+TextBox3.Text+"'";
             
            SqlCommand cmd = new SqlCommand(str, con);

          
            con.Open();
          
            SqlDataReader dr = cmd.ExecuteReader();

            if ((dr.Read()))
            {
                error.Text = "Sucessfully Login";
        
                con.Close();
            }
            else
            {
                error.Text = "Wroung Password";
            }

       

        }
        catch (Exception ex)
        {
            error.Text = "Error" + ex;
        }
    }
}

 

Important Codings

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

namespace Ranjeet_calculator
{
    public partial class Form1 : Form
    {
#1#
        bool plus = false;
        bool minus = false;
        bool multiply = false;
        bool divide = false;
        bool equal = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void ( * coding)button15_Click(object sender, EventArgs e)
        {



            if (textBox1.Text == "")
            {
                textBox1.Text = "";
                equal = false;
                return;
            }
            else
            {
                multiply = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";

            }
        }

        private void ChekifEqual()
        {

            if (equal)
            {
                textBox1.Text = "";
                equal = false;
            }
        }

        private void ( = coding) button18_Click(object sender, EventArgs e)
        {
          
           
            equal = true;
            if (plus)
            {
               

                   
               
                decimal dec = Convert.ToDecimal(textBox1.Tag) + Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();
            }

            if (minus)
            {
                decimal dec = Convert.ToDecimal(textBox1.Tag) - Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();


            }


            if (multiply)
            {
                decimal dec = Convert.ToDecimal(textBox1.Tag) * Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();
            }

            if (divide)
            {
                decimal dec = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();
            }
               
              
                   
               
       

        }
        private void ( 1 coding)button1_Click(object sender, EventArgs e)
        {
            CeckifEqual();
            if (equal)
            {

                textBox1.Text = "";
                equal = false;
            }

            textBox1.Text = textBox1.Text + "1";
        }

        private void CeckifEqual()
        {
            if (equal)
            {

                textBox1.Text = "";
                equal = false;
            }

        }
        private void ( 2 coding)button2_Click(object sender, EventArgs e)
        {

            CeckifEqual();

            textBox1.Text = textBox1.Text + "2";
        }

        private void ( 3 coding)button3_Click(object sender, EventArgs e)
        {

            CeckifEqual();

            textBox1.Text = textBox1.Text + "3";
        }

        private void ( 4 coding)button4_Click(object sender, EventArgs e)
        {
            CeckifEqual();

            textBox1.Text = textBox1.Text + "4";
        }

        private void ( 5 coding)button5_Click(object sender, EventArgs e)
        {
            CeckifEqual();
            textBox1.Text = textBox1.Text + "5";
        }

        private void ( 6 coding)button6_Click(object sender, EventArgs e)
        {
            CeckifEqual();
            textBox1.Text = textBox1.Text + "6";
        }

        private void ( 7 coding)button7_Click(object sender, EventArgs e)
        {

            CeckifEqual();
            textBox1.Text = textBox1.Text + "7";
        }

        private void ( 8 coding)button8_Click(object sender, EventArgs e)
        {

            CeckifEqual();
            textBox1.Text = textBox1.Text + "8";
        }

        private void ( 9 coding)button9_Click(object sender, EventArgs e)
        {
            CeckifEqual();

            textBox1.Text = textBox1.Text + "9";
        }

        private void ( . coding)button11_Click(object sender, EventArgs e)
        {

            if (textBox1.Text.Contains("."))
            {
                return;
            }
            else
            {
                textBox1.Text = textBox1.Text + ".";

            }
        }

        private void ( +/- coding)button12_Click(object sender, EventArgs e)
        {

            if (textBox1.Text.Contains("-"))
            {
                textBox1.Text = textBox1.Text.Remove(0, 1);
            }
            else
            {
                textBox1.Text = "-" + textBox1.Text;

            }
        }

        private void ( + coding)button13_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                plus = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";
            }
        }

        private void ( - coding) button14_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                minus = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";
            }

        }

        private void ( / divide coding)button16_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                divide = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";

            }
        }

        private void (c,clear coding) button17_Click(object sender, EventArgs e)
        {
            plus = minus = multiply = divide = equal = true;
            textBox1.Text = "";
            textBox1.Tag = "";
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();




        }

        private void developerPhotoToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Form2 r = new Form2();
            r.Show();
            this.Hide();
        }

        private void ( 0 coding)button10_Click(object sender, EventArgs e)
        {
            CeckifEqual();
            textBox1.Text = textBox1.Text + "0";
        }
       

        private void textBox1_TextChanged(object sender, EventArgs e)
        {


            if (textBox1.Text != "")
                try
                {
                    textBox1.Text = Convert.ToDecimal(textBox1.Text.Replace("$", "").Replace(",", "")).ToString("");
              
                }
                catch
                {
                    MessageBox.Show("Please enter Numeric value input");
                    textBox1.Clear();
                  
                }
        }
    }
}


.......................................Notepad Coding.............................


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

namespace Ranjeet_NotePad
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void (new coding)newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void (open coding)openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            {
                OpenFileDialog ranjeet = new OpenFileDialog();
                ranjeet.Title = "open";
                ranjeet.Filter = "All Files|*.*";

                try
                {
                    if (ranjeet.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        richTextBox1.LoadFile(ranjeet.FileName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("invilid File format");

                }



            }
        }

        private void (save coding)saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            {
                SaveFileDialog s = new SaveFileDialog();

                s.Title = "Save";
                s.Filter = "Rich Text Files |*.rtf";

                try
                {
                    if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        richTextBox1.SaveFile(s.FileName);
                    }
                }
                catch (Exception ex)
                {


                }
            }
        }

        private void (exit coding)exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void (undo coding)undoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Undo();
        }

        private void (redo coding)redoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Redo();
        }

        private void (cut coding)cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Cut();
        }

        private void (copy coding)copyToolStripMenuItem_Click(object sender, EventArgs e)
        {

            richTextBox1.Copy();

        }

        private void (past coding)pastToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Paste();
        }

        private void (clear coding)clearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void (select all coding)sellectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.SelectAll();
        }

        private void (font coding)fontToolStripMenuItem_Click(object sender, EventArgs e)
        {



            {
                FontDialog Font = new FontDialog();

                try
                {
                    Font.Font = richTextBox1.SelectionFont;

                    if (Font.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        richTextBox1.SelectionFont = (Font)Font.Font.Clone();
                    }
                }
                catch (Exception ex)
                {
                }

            }
        }

        private void (colour coding)colourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            {
                ColorDialog Colour = new ColorDialog();

                try
                {
                    Colour.Color = richTextBox1.SelectionColor;


                    if (Colour.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        richTextBox1.SelectionColor = Colour.Color;
                    }

                }
                catch (Exception ex)
                {
                }

            }
        }

        private void developerPhotoToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Form2 r = new Form2();
            r.Show();
            this.Hide();
        }

        private void (exit coding)exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void (clear coding)clearToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void (save coding)saveToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            {
                SaveFileDialog s = new SaveFileDialog();

                s.Title = "Save";
                s.Filter = "Rich Text Files |*.rtf";

                try
                {
                    if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        richTextBox1.SaveFile(s.FileName);
                    }
                }
                catch (Exception ex)
                {


                }
            }
        }

        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.SelectAll();
        }

        private void cutToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            richTextBox1.Cut();
        }

        private void copyToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            richTextBox1.Copy();
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Paste();
        }

        private void formatToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void cToolStripMenuItem_Click(object sender, EventArgs e)
        {


            {
                FontDialog Font = new FontDialog();

                try
                {
                    Font.Font = richTextBox1.SelectionFont;

                    if (Font.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        richTextBox1.SelectionFont = (Font)Font.Font.Clone();
                    }
                }
                catch (Exception ex)
                {
                }


            }
        }

        private void colourToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            {
                ColorDialog Colour = new ColorDialog();

                try
                {
                    Colour.Color = richTextBox1.SelectionColor;


                    if (Colour.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        richTextBox1.SelectionColor = Colour.Color;
                    }

                }
                catch (Exception ex)
                {
                }

            }
        }

        private void undoToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            richTextBox1.Undo();
        }

        private void redoToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            richTextBox1.Redo();
        }
    }
}
................................Check Database Connection Coding............................
check connec tion Open yes or not

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


namespace Image_Save
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       ##2## SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=gun; User Id=sa; Password=sapna");

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

     ### 3 ##       con.Open();
            if(con.State.ToString() == "Open")
            {
                MessageBox.Show("hi");
            }
        }

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

.....................................Demo2_project_double_photo_stor_coding..........................

                     ............DATABASE..............
create database check1
CREATE TABLE [dbo].[check]
(

    [Id] [int] IDENTITY (1, 1) NOT NULL ,
    [Name] [varchar] (50) NOT NULL,
    [Address] [varchar] (150) NOT NULL,
    [Phone] [varchar] (15) NOT NULL,
    [OriginalPath] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
   
[gPath] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Photo] [image] NOT NULL,

   
[gunPhoto] [image] NOT NULL





) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

select * from [check]


............................Coding.........................

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

namespace Demo_Project
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=check1; User Id=sa; Password=sapna");
        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            show_detail();

        }
        public void clear()
        {
            textId.Text = "";
            textName.Text = "";
            textAddress.Text = "";
            textPhone.Text = "";
            textPhoto_Path.Text = "";
            textgpath.Text = "";
        }


        public void show_detail()
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from [check]", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "[check]");
            dataGridView1.DataSource = ds.Tables["[check]"];
            con.Close();
        }

        private void (save coding)button2_Click(object sender, EventArgs e)
        {
            byte[] Photo = ReadFile(textPhoto_Path.Text);
            byte[] gunPhoto = ReadFile(textgpath.Text);
            try
            {

                string str = "insert into [check] (Name,Address,Phone,OriginalPath,gPath,Photo,gunPhoto) values(@Name,@Address,@Phone,@OriginalPath,@gPath,@Photo,@gunPhoto)";
                SqlCommand cmd = new SqlCommand(str, con);
                cmd.Parameters.Add(new SqlParameter("@Name", (object)textName.Text));
                cmd.Parameters.Add(new SqlParameter("@Address", (object)textAddress.Text));
                cmd.Parameters.Add(new SqlParameter("@Phone", (object)textPhone.Text));
              
                cmd.Parameters.Add(new SqlParameter("@OriginalPath", (object)textPhoto_Path.Text));

                cmd.Parameters.Add(new SqlParameter("@gPath", (object)textgpath.Text));

                cmd.Parameters.Add(new SqlParameter("@Photo", (object)Photo));
                cmd.Parameters.Add(new SqlParameter("@gunPhoto", (object)gunPhoto));


                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Saved Successfully");
                show_detail();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }




        private void (add coding)button1_Click(object sender, EventArgs e)
        {
        //    con.Open();
        //    if (con.State.ToString() == "Open")
        //    {
        //        MessageBox.Show("hi");
        //    }
            textName.Enabled = true;
            textAddress.Enabled = true;
            textPhone.Enabled = true;
            textPhoto_Path.Enabled = true;
            textgpath.Enabled = true;


            clear();

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void#(first photo(your_photo) browser coding)# button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog fl = new OpenFileDialog();
            DialogResult dl = fl.ShowDialog();
            if (dl != DialogResult.Cancel)
            {
                pictureBox1.ImageLocation = fl.FileName;
                textPhoto_Path.Text = fl.FileName;

            }
        }
        byte[] ReadFile(String spath)
        {
            byte[] data = null;
            FileInfo finfo = new FileInfo(spath);
            long numbyts = finfo.Length;
            FileStream fs = new FileStream(spath, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            data = br.ReadBytes((int)numbyts);
            return data;


        }

        private void (writre click datagredeview and write click and go to even cell enter double click and write)dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            string row;
            string row1;
            string row2;
            string row3;
            string row4;
            string row5;
            row = dataGridView1.CurrentRow.Cells["Name"].Value.ToString();
            textName.Text = row;
            row1 = dataGridView1.CurrentRow.Cells["Id"].Value.ToString();
            textId.Text = row1;
            row2 = dataGridView1.CurrentRow.Cells["Address"].Value.ToString();
            textAddress.Text = row2;
            row3 = dataGridView1.CurrentRow.Cells["Phone"].Value.ToString();
            textPhone.Text = row3;
            row4 = dataGridView1.CurrentRow.Cells["OriginalPath"].Value.ToString();
            textPhoto_Path.Text = row4;

            row5 = dataGridView1.CurrentRow.Cells["OriginalPath"].Value.ToString();
            textgpath.Text = row5;
            try
            {
                byte[] Photo = (byte[])dataGridView1.Rows[e.RowIndex].Cells["Photo"].Value;
                Image newImage;
                using (MemoryStream ms = new MemoryStream(Photo, 0, Photo.Length))
                {
                    ms.Write(Photo, 0, Photo.Length);
                    newImage = Image.FromStream(ms, true);
                }
                pictureBox1.Image = newImage;


                byte[] gunPhoto = (byte[])dataGridView1.Rows[e.RowIndex].Cells["gunPhoto"].Value;
                Image newImage1;
                using (MemoryStream ms = new MemoryStream(gunPhoto, 0, gunPhoto.Length))
                {
                    ms.Write(gunPhoto, 0, gunPhoto.Length);
                    newImage1 = Image.FromStream(ms, true);
                }
                pictureBox2.Image = newImage1;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


       

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void (3 update coding)button3_Click(object sender, EventArgs e)
        {
            byte[] Photo = ReadFile(textPhoto_Path.Text);
            byte[] gPhoto = ReadFile(textgpath.Text);
            try
            {
                string str = "update [check] set Name=@Name,Address=@Address,Phone=@Phone,OriginalPath=@OriginalPath,gPath=@gPath,Photo=@Photo,gunPhoto=@gunPhoto where Id='" + textId.Text + "'";
                SqlCommand cmd = new SqlCommand(str, con);
                cmd.Parameters.Add(new SqlParameter("@Name", (object)textName.Text));
                cmd.Parameters.Add(new SqlParameter("@Address", (object)textAddress.Text));
                cmd.Parameters.Add(new SqlParameter("@Phone", (object)textPhone.Text));
                cmd.Parameters.Add(new SqlParameter("@OriginalPath", (object)textPhoto_Path.Text));
               
                cmd.Parameters.Add(new SqlParameter("@gPath", (object)textgpath.Text));
                cmd.Parameters.Add(new SqlParameter("@Photo", (object)Photo));
                cmd.Parameters.Add(new SqlParameter("@gunPhoto", (object)gPhoto));
              
              
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Updated Successfully");
                show_detail();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void (delete coding)button5_Click(object sender, EventArgs e)
        {

            try
            {
                if (textDelete.Text == "")
                {
                    MessageBox.Show("Please enter a valid ID.");
                }
                else
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("delete from [check] where Id='" + textDelete.Text + "'", con);
                    cmd.ExecuteNonQuery();
                    con.Close();

                    MessageBox.Show("Deleted successfully");
                    show_detail();

                    textDelete.Text = "";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void (search coding)textSearch_TextChanged(object sender, EventArgs e)
        {
            if (textSearch.Text == "")
            {
                show_detail();
            }
            else
            {
                try
                {


                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter("select * from [check] where Id LIKE '" + textSearch.Text + "%'", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "[check]");
                    dataGridView1.DataSource = ds.Tables["[check]"];
                    con.Close();
                }


                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void #(second photo(your_gf_photo) browser coding)#button6_Click(object sender, EventArgs e)
        {
           
            OpenFileDialog fl1 = new OpenFileDialog();# object should be change#
            DialogResult dll = fl1.ShowDialog();
            if (dll != DialogResult.Cancel)
            {
                pictureBox2.ImageLocation = fl1.FileName;
                textgpath.Text = fl1.FileName;

            }
        }
        byte[] ReadFile1(String spath)
        {
            byte[] data = null;
            FileInfo finfo = new FileInfo(spath);
            long numbyts = finfo.Length;
            FileStream fss = new FileStream(spath, FileMode.Open, FileAccess.Read);
            BinaryReader brr = new BinaryReader(fss);
            data = brr.ReadBytes((int)numbyts);
            return data;


        }

        }
    }
.............................Delete by Id Coding................

 try
            {
                if (txtsearch.Text == "")
                {
                    MessageBox.Show("Please enter a valid ID.");
                }

                else if (txtid.Text == txtsearch.Text)
                {
                    con.Open();

                    SqlCommand cmd = new SqlCommand("delete from ImagesStore where Employee_Id='" + txtsearch.Text + "'", con);
                    cmd.ExecuteNonQuery();
                    con.Close();

                    MessageBox.Show("Deleted successfully");
                    detail();

                    txtdelete.Text = "";
                    con.Close();
                }
                else
                {
                    MessageBox.Show("Id not matched");
                }
               
          
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

..............................Search by Name Coding....................
 try
            {
                if (comboBox1.Text == "Name")
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter("select * from ImagesStore where Employee_Name LIKE '" + txtsearch.Text + "%'", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "ImagesStore");
                    dataGridView1.DataSource = ds.Tables["ImagesStore"];
                    con.Close();

                }
                else if (comboBox1.Text == "Id")
                {



                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter("select * from ImagesStore where Employee_Id LIKE '" + txtsearch.Text + "%'", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "ImagesStore");
                    dataGridView1.DataSource = ds.Tables["ImagesStore"];
                    con.Close();
                }
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


..........................................Login Coding.................
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;

namespace Login_demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=LOGININFO;Integrated Security = true");


        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("Select * from GETGO where USERID ='" + textBox1.Text + "' AND PASSWORD ='" + textBox2.Text + "'", cn);

                cn.Open();
                SqlDataReader dr =  cmd.ExecuteReader();
            
                if ((dr.Read()))
                {

                    hii h1 = new hii();
                    h1.Show();
                    this.Hide();
                    cn.Close();
                }
                else
                {
                    MessageBox.Show("PLEASE ENTER THE VALID USERID & PASWWORD");
                    textBox1.Clear();
                    textBox2.Clear();
                }
            }
                catch(Exception exc)
            {
           
           
                    MessageBox.Show(exc.Message);
               
       
       
        }
    }
    }
}