Thursday 28 August 2014

Export Datatable value to Excel in asp.net c#

Hi Everyone in this article  have shown how to export data table value in excel .
basically I don't have ms office installed so i  have opened with browser.
basically that is html table i  am generating but because i have given .xls extension so we can open it in
excel also.

so whatever e column u have included in stored procedure will come in report.
just pass data table value or rows and any file name so it will take all rows from table and convert them into
html format so we can open in excel also.
lets have a look.

 On buttonclick it will export
protected void btnExport_Click(Object sender, EventArgs e)
    {
     
        ExportDataToExcelUsingDataTable((DataTable)ViewState["table"], "Report For User" + DateTime.Now.ToShortDateString() + ".xls");

    }


function to convert datatable record or data to excel format like 
public void ExportDataToExcelUsingDataTable(DataTable DtRecordOfUser, string FlNm)
    {
        try
        {
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + FlNm);
            HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
            string tab = string.Empty;

            HttpContext.Current.Response.Write("<table width='100%' border='1' " + "cellSpacing='0' cellPadding='0' " +


"style='font-size:11.0pt;'> <tr style='font-size:12pt;'>");


            for (int j = 0; j < DtRecordOfUser.Columns.Count; j++)

            {

                HttpContext.Current.Response.Write("<td  style='background-color:#339999;color:#FFF878;'>");

                HttpContext.Current.Response.Write("<B>");
                HttpContext.Current.Response.Write(DtRecordOfUser.Columns[j].ColumnName.ToString());
                HttpContext.Current.Response.Write("</B>");
                HttpContext.Current.Response.Write("</td>");
            }
            HttpContext.Current.Response.Write("</tr>");
            foreach (DataRow row in DtRecordOfUser.Rows)
            {

                HttpContext.Current.Response.Write("<tr>");

                for (int i = 0; i < DtRecordOfUser.Columns.Count; i++)
                {
                    HttpContext.Current.Response.Write("<td  style='background-color:#FFFBD6;color:#333333;'>");
                    HttpContext.Current.Response.Write(row[i].ToString());
                    HttpContext.Current.Response.Write("</td>");
                }

                HttpContext.Current.Response.Write("</tr>");

            }
            

            HttpContext.Current.Response.Write("</table>");

            HttpContext.Current.Response.Write("</font>");
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
        catch (Exception ex)
        {
            
        }

    }



export to excel using table



Wednesday 27 August 2014

Generate Dynamic table in html format in .cs page | Table Report | Design Report in asp.net with c#

Hi Everyone  in this article i am going to show how to generate dynamic table or we can say clone of grid view
with code behind .
we dont need to add any new control just apply css on code behind page and generate table with data.
i have shown both example with grid view and aslo with dynamic generated table with examples code.


0-> declare public string strDisplayDynamicTableReport = ""; before page load
1-> to take public string so we can assign string and then append on .aspx page like server control.
2-> We can bind our declare css also.
strDisplayDynamicTableReport += "<table cellpadding='0' cellspacing='0' border='1' bordercolor='red' >";
3->count table rows

for (int cnt = 0; cnt < DtGetAllEmoRecord.Rows.Count; cnt++)

4-> while  there is record in table add record in string and then print in html format.
by adding .aspx page

             <div>

                        <%=strDisplayDynamicTableReport%>

                  </div>


code for gridview


<asp:GridView runat="server" ID="grddata" AllowPaging="True" AutoGenerateColumns="false" DataKeyNames="NAME">
      <Columns>
          <asp:BoundField DataField="NAME" HeaderText="Name" ReadOnly="True"
              SortExpression="NAME" />
               <asp:BoundField DataField="NUMBER" HeaderText="Number" ReadOnly="True"
              SortExpression="NUMBER" />
               <asp:BoundField DataField="MAIL" HeaderText="Email Id" ReadOnly="True"
              SortExpression="MAIL" />
              <asp:TemplateField HeaderText="Delete">
              <ItemTemplate>
              <asp:LinkButton runat="server" ID="lnkdele" Text="delete" OnClick="lnkdele_click"></asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateField>
                <asp:TemplateField HeaderText="Edit">
              <ItemTemplate>
              <asp:LinkButton runat="server" ID="lnkedit" Text="Edit" OnClick="lnkedit_click"></asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateField>
      </Columns>
      <EmptyDataRowStyle BackColor="#FF9999" BorderStyle="Dashed" />
     
    </asp:GridView>



just call below function on page load or any control event..




private void DiplayAllREcord()
    {
       
        SqlDataAdapter sda = new SqlDataAdapter("Sp_InsertUpadetData 'SELECT','','','',''", sqcon);
        DataTable DtGetAllEmoRecord = new DataTable();
        sda.Fill(DtGetAllEmoRecord);
      
       if (DtGetAllEmoRecord != null && DtGetAllEmoRecord.Rows.Count > 0)
        {
            strDisplayDynamicTableReport += "<div id='UserDetails'>";
            strDisplayDynamicTableReport += "<table cellpadding='0' cellspacing='0' border='1' bordercolor='red' >";
            strDisplayDynamicTableReport += "<tr>";
            strDisplayDynamicTableReport += "<td width='150'><b>Employee Name:</b> </td>";
            strDisplayDynamicTableReport += "<td width='150'><b>Employee Number:</b> </td>";
            strDisplayDynamicTableReport += "<td width='150'><b>Employee Email:</b> </td>";
            strDisplayDynamicTableReport += "</tr>";
            for (int cnt = 0; cnt < DtGetAllEmoRecord.Rows.Count; cnt++)
            {
              
                strDisplayDynamicTableReport += "<tr>";
                strDisplayDynamicTableReport += "<td width='200'>" + DtGetAllEmoRecord.Rows[cnt]["NAME"].ToString() + "</td>";
                strDisplayDynamicTableReport += "<td width='200'>" + DtGetAllEmoRecord.Rows[cnt]["NUMBER"].ToString() + "</td>";
                strDisplayDynamicTableReport += "<td width='200'>" + DtGetAllEmoRecord.Rows[cnt]["MAIL"].ToString() + "</td>";
                strDisplayDynamicTableReport += "</tr>";
               
            }
            strDisplayDynamicTableReport += "</table>";
            strDisplayDynamicTableReport += "</div>";
        }
        grddata.DataSource = DtGetAllEmoRecord;
        grddata.DataBind();
       
 
    }



how to merge row in gridview when value is same

hi guys in this article i am  going to show you how to merge rows in grid view it two rows has same value.
idea is very simple to check if next and previous rows has some equal data then merge that number of rows.using col span.

lets have a look.



Now here there is no mathing value now m entering one matching value.

now here is name and number is same for dev so after click on merge button we will merge both row in same row and other will in different column.
here is code

protected void btnExport_Click(Object sender, EventArgs e)
{

    MergeRows(grddata);

}

public void MergeRows(GridView gridView)
{
    for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
    {
        GridViewRow row = gridView.Rows[rowIndex];
        GridViewRow previousRow = gridView.Rows[rowIndex + 1];

        if (row.Cells[0].Text == previousRow.Cells[0].Text && row.Cells[1].Text == previousRow.Cells[1].Text)
        {
            row.Cells[0].RowSpan = (previousRow.Cells[0].RowSpan < 2) ? 2 : previousRow.Cells[0].RowSpan + 1;
            previousRow.Cells[0].Visible = false;
            row.Cells[1].RowSpan = (previousRow.Cells[1].RowSpan < 2) ? 2 : previousRow.Cells[1].RowSpan + 1;
            previousRow.Cells[1].Visible = false;
        }
    }
}

How to Export Gridview data in excel format in c# asp.net with example


Hi everyone in this article i am going to show you how to Export gridview  data into excel.

first thing is that you should have  Ms offices installed i don't have installed but i will show you in browser.


lets get the code which will fill the grid .i am using visual studio 2010 and database is Sql server 2008.


private void DiplayAllREcord()
    {
       
        SqlDataAdapter sda = new SqlDataAdapter("Sp_InsertUpadetData 'SELECT','','','',''", sqcon);
        DataTable DtGetAllEmoRecord = new DataTable();
        sda.Fill(DtGetAllEmoRecord);
        grddata.DataSource = DtGetAllEmoRecord;
        grddata.DataBind();

       
       }


this is my code to fill grid view before post back .
now my button to export code behind code

protected void btnExport_Click(Object sender, EventArgs e)
{
    ExportExcelusingGridview(grddata, "Report For User" + DateTime.Now.ToShortDateString() + ".xls");
}





now i have given code to export gridview data to excel  as i dont have  MS - office installed so i m going to show in browser.

public void ExportExcelusingGridview(GridView grd, string fileName)
    {
        StringBuilder sbDocBody = new StringBuilder(); ;
        try
        {


            if (grd.Rows.Count > 0)
            {


                sbDocBody.Append("<table width='100%' border='1' " + "cellSpacing='0' cellPadding='0' " +

"style='font-size:11.0pt;'> <tr style='font-size:12pt;'>");
                // Add Data Rows
                for (int j = 0; j < grd.HeaderRow.Cells.Count; j++)
                    sbDocBody.Append("<td style='background-color:#ECE9D8;color:#000000;' width=\"120\"><B>" +

grd.HeaderRow.Cells[j].Text + "</B></td>");
                sbDocBody.Append("</tr>");
                for (int i = 0; i < grd.Rows.Count; i++)
                {
                    sbDocBody.Append("<tr>");
                    for (int j = 0; j < grd.Rows[i].Cells.Count; j++)
                    {
                        sbDocBody.Append("<td style='background-color:#FFFFE8;color:#333333;'>" + grd.Rows[i].Cells[j].Text +

"</td>");
                    }
                    sbDocBody.Append("</tr>");
                }
                sbDocBody.Append("<tr>");
                for (int j = 0; j < grd.FooterRow.Cells.Count; j++)
                {
                    sbDocBody.Append("<td style='background-color:#ECE9D8;color:#fff;' width=\"120\"

style='text-align:left'>" + grd.FooterRow.Cells[j].Text + "</td>");
                }
                sbDocBody.Append("</tr>");
                sbDocBody.Append("</table>");

            }
            else
                sbDocBody.Append("No records to export !!");

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.AppendHeader("Content-Type", "application/ms-excel");
            HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
            HttpContext.Current.Response.Write(sbDocBody.ToString());
            HttpContext.Current.Response.End();
        }
        catch (Exception ex)
        {
            //
        }
    }



so after click on excel it will appear like this..in browser but u can save it and if you need open with excel also.just copy code  ans paste it will work fine .just remember two things to include.
using System.Drawing;
using System.Text; //for string builder
using System.Web; // for httpcontext



Fetch all text box value into array

Fetch all text box value into array
hi everyone in this article i have shown how to fetch text box value or words or characters and use it like array
means to fetch all value which has entered in text  box and then restore each single value into array.


what i did i just took text box value into string and  had count length of string will be max array length so there be
no index-out of range  error will be come.

then using for loop count length and store each single value into array.
here is code



string  stringarrayvalue=Txtmytextboxvalue.text
        int[] aarr=new int [Txtmytextboxvalue.Text.Length];

//or u can take         int[] aarr=new int [stringarrayvalue.Length]; both will work




        for (int i = 0; i < stringarrayvalue.Length; i++)
        {


            aarr[i] =Convert.ToInt32(stringarrayvalue[i].ToString());

            Label lbli = new Label();

            lbli.Text = aarr[i].ToString();

            dvlabl.Controls.Add(lbli);

// took dynamic lable to display value
         



        }

this code is working fine.just copy and  paste  it .but label is dynamic u can take asp label.

how to generate dynamic controls text box , label in c# , asp.net.

how to  generate dynamic  controls text box , label in c# , asp.net.
how to  generate dynamic  controls text box , label in c# , asp.net.

in this article i have show how to generate dynamic control in asp.net and bind with existing control like Div .dynamic means

it will generate on run time .
first we will assign that attribute and then initialize new value .



To Generate Dynamic button
.cs page

    Button btnaddarray = new Button();
        btnaddarray.Text = "Add Array"; // Give text to respective button
        btnaddarray.ID = "BtnaddArray";   // provide id
        btnaddarray.Attributes.Add("Onclick", "BtnaddArray_Onclick"); // add event means when buton click  then event will be raised.



Now here i have called FunArray() function to generate dynamic controls in c# .
just copy or read this code and execute it.

private void FunArray()
    {
        int[] myArray = new int[10];
         myArray[0]=1;
        myArray[2]=2;
        myArray[3] = 3;
      
        Label lblPrintarrayvalue = new Label();
        lblPrintarrayvalue.Text =Convert.ToString("Array One:-" + myArray[0] +"Array Two:-"+"</Br>"+ myArray[1]+"Array

Three:-"+ myArray[2]+"<br/>");
        dvlabl.Controls.Add(lblPrintarrayvalue);
        lblPrintarrayvalue.ForeColor= System.Drawing.Color.Red;
        Response.Output.Write(lblPrintarrayvalue.Text);
        Response.Output.Write("<p>Your total is ${0:F2}</p>", lblPrintarrayvalue.Text);
        Response.Write(String.Format("<p>Your total is ${0:F2}</p>", lblPrintarrayvalue.Text));
        TextBox txttakeval = new TextBox();
        txttakeval.ID = "txtval";
        Label lblenterarray = new Label();
        lblenterarray.Text = "Enter Array List";
        txttakeval.Attributes.Add("Runat", "Server");
        Button btnaddarray = new Button();
        btnaddarray.Text = "Add Array";
        btnaddarray.ID = "BtnaddArray";
        btnaddarray.Attributes.Add("Onclick", "BtnaddArray_Onclick");

        btnaddarray.Click += new EventHandler(this.BtnaddArray_Onclick);
        dvlabl.Controls.Add(lblenterarray);
        dvlabl.Controls.Add(txttakeval);
        dvlabl.Controls.Add(btnaddarray);
      
      
      
    }

  private void BtnaddArray_Onclick(object sender, EventArgs e)
    {
//        your code

     
    }

.aspx page

 <div runat="server" id="dvlabl">
  <asp:Button runat="server" ID="btnsubmit"  Text="Submit" OnClick="btnsubmit_onclick" ValidationGroup="nm" />

  <asp:TextBox runat=server ID=txt2ley></asp:TextBox>
  </div>

Tuesday 26 August 2014

Fetch msg from sql server to c# code behind using execute scalar with validation

hi Everyone in this article i have shown how to get string or message from sql sever and to

display in c# code behind page with using output parameter with Execute Scalar method with

Insert and update and delete with Gridview with .aspx and .cs code.


so we can use execute non query also but that will return only zero & 1.
so we have used Execute Scalar so we can fetch message which we have return in sql server.
i have also shown execution part in  code behind.



default.aspx page.


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

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Inert update and delete in gridview
    </h2>
  <div>
  <asp:Label runat="server" Text="Enter Name" style="width:290px;"></asp:Label><input type="text"  runat="server" id="inptnm" placeholder="Enter  name"/>
  <asp:RequiredFieldValidator  runat="server"  id="rqres" ControlToValidate="inptnm" Text="*" ValidationGroup="nm"   ForeColor="Red" InitialValue=""></asp:RequiredFieldValidator>
  </div>
  <div>
  <br />
  <asp:Label runat="server"  Text="Enter number"></asp:Label><input type="text" runat="server" id="txtnumber"  text="*" placeholder="Enter  number" maxlength="10"/>
  <asp:RequiredFieldValidator  runat="server"  id="RequiredFieldValidator1" ControlToValidate="txtnumber" Text="*" ValidationGroup="nm"   ForeColor="Red" InitialValue=""></asp:RequiredFieldValidator>
      <asp:CompareValidator ID="CompareValidator1" runat="server"
          ErrorMessage="Pleas Enter Integer" ControlToValidate="txtnumber"
          Operator="DataTypeCheck" Type="Integer" ValidationGroup="nm"></asp:CompareValidator>
 

  </div>

    <div>
  <br />
  <asp:Label ID="Label1" runat="server"  Text="Enter Email"></asp:Label><input type="text" runat="server" id="txtmail"  text="*" placeholder="Enter  Mail"/>

<asp:RequiredFieldValidator  runat="server"  id="RequiredFieldValidator2" ControlToValidate="txtmail" Text="*" ValidationGroup="nm"   ForeColor="Red" InitialValue=""></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator
                ID="RegularExpressionValidator1" runat="server"
            ErrorMessage="Please enter Proper address" ControlToValidate="txtmail"  ValidationGroup="nm"
           
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

 

  </div>
  <asp:Button runat="server" ID="btnsubmit"  Text="Submit" OnClick="btnsubmit_onclick" ValidationGroup="nm" />
  <br />
  <asp:GridView runat="server" ID="grddata" AllowPaging="True" AutoGenerateColumns="false" DataKeyNames="NAME">
      <Columns>
          <asp:BoundField DataField="NAME" HeaderText="Name" ReadOnly="True"
              SortExpression="NAME" />
               <asp:BoundField DataField="NUMBER" HeaderText="Number" ReadOnly="True"
              SortExpression="NUMBER" />
               <asp:BoundField DataField="MAIL" HeaderText="Email Id" ReadOnly="True"
              SortExpression="MAIL" />
              <asp:TemplateField HeaderText="Delete">
              <ItemTemplate>
              <asp:LinkButton runat="server" ID="lnkdele" Text="delete" OnClick="lnkdele_click"></asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateField>
                <asp:TemplateField HeaderText="Edit">
              <ItemTemplate>
              <asp:LinkButton runat="server" ID="lnkedit" Text="Edit" OnClick="lnkedit_click"></asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateField>
      </Columns>
      <EmptyDataRowStyle BackColor="#FF9999" BorderStyle="Dashed" />
     
    </asp:GridView>
    <asp:HiddenField runat="server" ID="hdnval" />
    <asp:HiddenField runat="server" ID="hdngetid" />

</asp:Content>






using System;
using System.Web.UI;
using  System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Web.Configuration;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
   SqlConnection sqcon=new SqlConnection(WebConfigurationManager.ConnectionStrings["constr"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack == true)
        {
            hdnval.Value = "I";
            DiplayAllREcord();
        }
    }

    protected void btnsubmit_onclick(object sender, EventArgs e)
    {

         try
        {
             SqlCommand cmd = new SqlCommand("Sp_InsertUpadetData", sqcon);
            cmd.CommandType = CommandType.StoredProcedure;
            if (hdnval.Value == "U")
            {
                cmd.Parameters.AddWithValue("@Action", "UPDATE");
                hdnval.Value = "I";
                btnsubmit.Text = "Submit";
            }
            else
            {
                cmd.Parameters.AddWithValue("@Action", "INSERT");
            }
            cmd.Parameters.AddWithValue("@name", inptnm.Value);
            cmd.Parameters.AddWithValue("@number", txtnumber.Value);
            cmd.Parameters.AddWithValue("@Mail", txtmail.Value);
            cmd.Parameters.AddWithValue("@Msg" ,"").Direction = ParameterDirection.Output; 
           
            object val;
                  sqcon.Open();

                val = cmd.ExecuteScalar();
               
                if (Convert.ToString(val) == "SU")
                {
                    //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "'" + "<script>alert('Data inseted succesfully');</script>");
                    Response.Write("<script>alert('Request Saved Successfully')</script>");
                   
                    inptnm.Value = "";
                    txtnumber.Value = "";
                    txtmail.Value = "";
                    DiplayAllREcord();
                }
                else
                {
                    Response.Write("<script>alert('Please Add Proper Data')</script>");
                    //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "'" + "<script>alert(Email id Exists);<script>");
                }

           
        }
        catch (Exception ex)
        { Response.Write (ex.ToString());}
        finally{
            sqcon.Close();
            sqcon.Dispose();
        }

    }
    private void DiplayAllREcord()
    {
       
        SqlDataAdapter sda = new SqlDataAdapter("Sp_InsertUpadetData 'SELECT','','','',''", sqcon);
        DataTable DtGetAllEmoRecord = new DataTable();
        sda.Fill(DtGetAllEmoRecord);
        grddata.DataSource = DtGetAllEmoRecord;
        grddata.DataBind();
    


    }

    protected void lnkdele_click(object sender, EventArgs e)
    {

        LinkButton lnkbtn = sender as LinkButton;
        //getting particular row linkbutton

        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;

        //getting userid of particular row
       
        string username =Convert.ToString(grddata.DataKeys[gvrow.RowIndex].Value.ToString());
      
      

        SqlCommand  sda = new  SqlCommand("Sp_InsertUpadetData 'Delete',"+username+",'','',''", sqcon);
        int del = 0;
        sqcon.Open();
        del = sda.ExecuteNonQuery();
        sqcon.Close();
        if (del > 0)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Msg", "'" + "<script>alert('REcored deleted Succesfully');</script>");
           
        }
       
        DiplayAllREcord();
    }
    protected void lnkedit_click(object sender, EventArgs e)
    {
        LinkButton lnkedit = sender as LinkButton;
        GridViewRow grrow = lnkedit.NamingContainer as GridViewRow;
        string strupdateval = Convert.ToString(grddata.DataKeys[grrow.RowIndex].Value.ToString());
        hdnval.Value = "U";
        hdngetid.Value = strupdateval.ToString();
        SqlDataAdapter sda = new SqlDataAdapter("Sp_InsertUpadetData 'EDIT',"+strupdateval.ToString()+",'','',''", sqcon);
        DataTable DtGetAllEmoRecord = new DataTable();
        sda.Fill(DtGetAllEmoRecord);
        inptnm.Value = DtGetAllEmoRecord.Rows[0]["NAME"].ToString();
        txtmail.Value = DtGetAllEmoRecord.Rows[0]["MAIL"].ToString();
        txtnumber.Value = DtGetAllEmoRecord.Rows[0]["NUMBER"].ToString();
        btnsubmit.Text = "Update";
      
    }
  
}

stored procedure


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER Procedure [dbo].[Sp_InsertUpadetData]
(
@Action varchar(20),
@name varchar(20),
@number  int ,
@Mail varchar(20),
@Msg varchar(20) out
)
AS
BEGIN
DECLARE @RETURN AS VARCHAR(20)
IF (@Action='INSERT')
    BEGIN
    IF EXISTS(SELECT @Mail FROM insertstudbvalue where MAIL=@Mail )
    BEGIN
    SET @Msg='ER'
    END
    ELSE
    BEGIN
    INSERT INTO insertstudbvalue VALUES(@name , @number, @Mail)
UPDATE insertstudbvalue SET NUMBER=@NUMBER , MAIL=@MAIL WHERE
NAME=@NAME
    SET @Msg='SU'
    END
SELECT @Msg
END
ELSE IF (@Action='SELECT')
BEGIN
SELECT NAME , NUMBER , MAIL FROM insertstudbvalue
END

ELSE IF (@Action='DELETE')
BEGIN
DELETE FROM insertstudbvalue WHERE  NAME=@NAME
END
ELSE IF (@Action='UPDATE')
BEGIN
   
    IF EXISTS(SELECT @Mail FROM insertstudbvalue where MAIL=@Mail And  NAME = @NAME)
    BEGIN
        UPDATE insertstudbvalue SET NUMBER=@NUMBER , MAIL=@MAIL WHERE
        NAME=@NAME
        SET @Msg='SU'
    END
    ELSE
    BEGIN
        IF EXISTS(SELECT @Mail FROM insertstudbvalue where MAIL=@Mail And  NAME <> @NAME)
            BEGIN
               
                SET @Msg='ER'
            END
    END
   
SELECT @Msg
END
ELSE IF (@Action='EDIT')
BEGIN
SELECT NAME , NUMBER , MAIL FROM insertstudbvalue WHERE
NAME=@NAME
END
END