Sunday, 31 August 2014

Insert,Select,Delete, Update by SQL Helper

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Update.aspx.cs" Inherits="WebApplication1.Update" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div><table>
       
       <tr><td><asp:Label ID="Label2" runat="server" Text="Name"></asp:Label></td><td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td></tr>
     
       <tr><td>
           <asp:Button ID="Button1" runat="server" onclick="Button1_Click1"
               Text="Update" />
           <asp:Button ID="Button2" runat="server" Text="Insert" onclick="Button2_Click" />
           </td></tr>
     
        </table>
       
    <table>
    <tr><td>
  <asp:GridView ID="Gridupdate" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
            CellPadding="4" OnPageIndexChanging="Gridstate_PageIndexChanging" OnRowDeleting="Gridupdate_RowDeleting"
            OnSelectedIndexChanged="Gridstate_SelectedIndexChanging" Width="100%" EmptyDataText="no record found">
                                <Columns>
                                 <asp:TemplateField>
                           <ItemTemplate>
                         
                             <asp:Label ID="ID" runat="server"
                                   Text='<%#Eval("Id")%>' Visible="false"></asp:Label>
                           </ItemTemplate>
                           </asp:TemplateField>
                                    <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True"
                                        SortExpression="Name" />
                                   
                                 
                                   <asp:HyperLinkField Text="Edit" DataNavigateUrlFields="Id" DataNavigateUrlFormatString="Update.aspx?Id={0}" />
                                 
                                   
                                 
                                   
                                 
                                    <asp:CommandField ShowDeleteButton="True" />
                                 
                                   
                                 
                                   
                                 
                                </Columns>
                                <EmptyDataTemplate>
                                    NO record
                                </EmptyDataTemplate>
                                <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                                <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                                <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                                <RowStyle BackColor="White" ForeColor="#003399" />
                                <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                            </asp:GridView>

     
                            <asp:HiddenField ID="hdn_update" runat="server" />
                            </td></tr>
    </table>
    </div>
    </form>
</body>
</html>


.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;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
namespace WebApplication1
{
    public partial class Update : System.Web.UI.Page
    {
        string str = System.Configuration.ConfigurationManager.AppSettings["SQLConnkuldeep"].ToString();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                show();
                if (Request.QueryString["Id"] != null)
                {
                    hdn_update.Value = Request.QueryString["Id"].ToString();
                    showpudate(Convert.ToInt32(hdn_update.Value));
                
                }
            }
        }
 
        public void show()
        {
            DataSet ds = SqlHelper.ExecuteDataset(str, CommandType.StoredProcedure, "sp_select");

            

                Gridupdate.DataSource = ds;
                Gridupdate.DataBind();
            
        }
        public void showpudate( int id)
        {
            SqlParameter[] prm = new SqlParameter[1];
            prm[0] = new SqlParameter("@id", Convert.ToInt32(id));
           

          
         DataSet ds=  SqlHelper.ExecuteDataset(str, CommandType.StoredProcedure, "sp_select1", prm);
          if (ds.Tables[0].Rows.Count > 0)
          {
            TextBox2.Text= ds.Tables[0].Rows[0]["name"].ToString();
          }
        }


        protected void Gridupdate_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Gridupdate.PageIndex = e.NewPageIndex;
            show();
        }

        protected void Gridupdate_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            
            string ID = ((Label)(Gridupdate.Rows[e.RowIndex].FindControl("Id"))).Text;
 SqlParameter[] prm = new SqlParameter[1];
            prm[0] = new SqlParameter("@id",ID);
           

           
           SqlHelper.ExecuteNonQuery(str, CommandType.StoredProcedure, "sp_delete", prm);
        
            show();
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {

            if (Request.QueryString["Id"] != null)
            {
                SqlParameter[] prm = new SqlParameter[3];
                prm[0] = new SqlParameter("@id", Convert.ToInt32(hdn_update.Value));

                prm[1] = new SqlParameter("@name", TextBox2.Text);



                prm[2] = new SqlParameter("@result", SqlDbType.Int);
                prm[2].Direction = ParameterDirection.ReturnValue;
                SqlHelper.ExecuteNonQuery(str, CommandType.StoredProcedure, "sp_update1", prm);

                Int32 check = Convert.ToInt32(prm[2].Value);

                if (check == 1)
                {
                    show();

                }
            }
            else {

                Response.Write("click on edit");
            }
        }

        protected void Gridstate_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Gridupdate.PageIndex = e.NewPageIndex;
            show();

        }

        protected void Gridstate_SelectedIndexChanging(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
SqlParameter[] prm = new SqlParameter[2];
            prm[0] = new SqlParameter("@name", TextBox2.Text);
       
           
           prm[1] = new SqlParameter("@result", SqlDbType.Int);
            prm[1].Direction = ParameterDirection.ReturnValue;
           SqlHelper.ExecuteNonQuery(str,CommandType.StoredProcedure,"sp_insert", prm);

         Int32 check = Convert.ToInt32(prm[1].Value);
          if (check == 1)
            {
       
                show();
             clear();

        }
        else 
    {
        Response.Write("hi");
                
    }
        }



        public void clear()
        {
            TextBox2.Text = string.Empty;
          
        }
        }
    }

 table........>>>

USE [test]
GO

/****** Object:  Table [dbo].[tbl_user]    Script Date: 08/31/2014 06:51:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[tbl_user](
[Id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NULL,
[Isactive] [bit] NULL,
 CONSTRAINT [PK_tbl_user] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[tbl_user] ADD  CONSTRAINT [DF_tbl_user_Isactive]  DEFAULT ((1)) FOR [Isactive]
GO

store procedure ......................>>>>


CREATE PROCEDURE [dbo].[sp_insert]
(
@name varchar(100)
--@result  Output
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- Insert statements for procedure here
insert into tbl_user
(
name
)
values
(
@name
)
--set @result =1
return 1  
END

Create  PROCEDURE [dbo].[sp_select]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- update statements for procedure here
select id, name from tbl_user where Isactive=1

 
end

ALTER PROCEDURE [dbo].[sp_select1]
(
@id int
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- update statements for procedure here
select * from tbl_user where Id=@id and  Isactive=1

return 1  
end

ALTER PROCEDURE [dbo].[sp_update1]
(
@id int,
@name varchar(100)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- update statements for procedure here
UPDATE tbl_user SET name=@name WHERE Id=@id

return 1  
end
ALTER PROCEDURE [dbo].[sp_delete]
(
@id int
--@result  Output
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- update statements for procedure here
update  tbl_user
set isactive=0
where Id=@id

return 1  
end

Saturday, 30 August 2014

Bind State detail in drop down


Bind state in dropdown

private void State()
     {
   
    DataTable dt= dal.StateMaster();
    DataRow dr = dt.NewRow();
    dr["State_ID"] = 0;
    dr["State_Name"] = "..Select..";
    dt.Rows.InsertAt(dr, 0);
    dt.AcceptChanges();
    ddl_state.DataSource = dt;

      ddl_state.DataTextField = "State_Name";
    ddl_state.DataValueField = "State_ID";
    ddl_state.DataBind();

}

 public DataTable StateMaster()
    {
      //  string connstr = Conaction.GetConnString();
       // SqlConnection con = new SqlConnection(connstr);

        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "ADD_UPDATE_STATE_MASTERSELECT";
        cmd.Connection = con;
        SqlDataAdapter adp = new SqlDataAdapter();
        adp.SelectCommand = cmd;
        DataSet ds = new DataSet();
     
        adp.Fill(ds);
        con.Close();
        return ds.Tables[0];


   
    }
Store procedure....>>>

create  PROCEDURE  [dbo].[ADD_UPDATE_STATE_MASTERSELECT]


AS
Select * from State_Master


Table Script.....>>

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[STATE_MASTER](
[State_ID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[State_Name] [varchar](50) NULL,
[State_Desc] [varchar](150) NULL,
 CONSTRAINT [PK_STATE_MASTER] PRIMARY KEY CLUSTERED
(
[State_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO



Insert Update Delete By Store Procedure

.ASP Page........>>>

<table id="Table1" cellspacing="0" cellpadding="0" width="780" align="center"
border="0">
<tr>
<td><uc1:header id="Header1" runat="server"></uc1:header></td>
</tr>
<tr>
<td height="15">
<uc1:Master_cntrl id="Master_cntrl1" runat="server"></uc1:Master_cntrl></td>
</tr>
<tr>
<td height="15"></td>
</tr>
<tr>
<td>
<P align="center"><strong><font face="Verdana" size="4"><U>State&nbsp;Master</U></font></strong></P>
</td>
</tr>
<tr>
<td height="15">
<P align="right"><font face="Verdana" size="2"><strong></strong></font>&nbsp;</P>
</td>
</tr>
<tr>
<td>
<table id="Table2" cellspacing="4" cellpadding="0" width="380" align="center" border="0">
<tr>
<td width="40%"><strong><font face="Verdana" size="2">State Name</font></strong></td>
<td><asp:textbox id="txt_SName" runat="server" Width="200px" MaxLength="50"></asp:textbox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txt_SName"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td><font face="Verdana" size="2"><strong>State Description</strong></font></td>
<td>
<asp:TextBox id="txt_SDesc" runat="server" Width="200px" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" class="style1"></td>
</tr>
<tr>
<td colspan="2">
<P align="center">
<asp:Label id="lbl_msg" runat="server" Font-Names="Verdana" Font-Size="12px" ForeColor="Red"
EnableViewState="False"></asp:Label></P>
</td>
</tr>
</table>

</td>
</tr>
<tr>
<td>
<P align="center">
<asp:Button id="btn_Add" runat="server" Text="Add" onclick="btn_Add_Click"
                                style="height: 26px" Height="30px" Width="100px"  Font-Bold=true ></asp:Button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btn_update" runat="server" Enabled="False" OnClick="btn_update_Click" Height="30px" Width="100px"  Font-Bold=true
                                Text="Update" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</P>
<P align="center"> <asp:HiddenField id="hdn_Sid" runat="server" Value="0"/>
                            <asp:HiddenField ID="hdn_Supdate" runat="server" />
                        </P>
                    </td>
</tr>
<tr>
<td height="15"></td>
</tr>
<tr>
<td height="300" vAlign="top" bgColor="#dcdcdc">
<DIV align="center">
                           
                            <asp:GridView ID="Gridstate" runat="server" BackColor="White"
                                BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
                                AutoGenerateColumns="False" Width="100%" AllowPaging="True"
                                onpageindexchanging="Gridstate_PageIndexChanging"
                                onselectedindexchanged="Gridstate_SelectedIndexChanging" onrowdeleting="Gridstate_RowDeleting"
                               >
                                <Columns>
                                 <asp:TemplateField>
                           <ItemTemplate>
                         
                             <asp:Label ID="ID" runat="server"
                                   Text='<%#Eval("State_ID")%>' Visible="false"></asp:Label>
                           </ItemTemplate>
                           </asp:TemplateField>
                                    <asp:BoundField DataField="State_Name" HeaderText="State Name" ReadOnly="True"
                                        SortExpression="State_Name" />
                                    <asp:BoundField DataField="State_Desc" HeaderText="Description"
                                        SortExpression="State_Desc" />
                                 
                                    <asp:HyperLinkField Text="Edit" DataNavigateUrlFields="State_ID" DataNavigateUrlFormatString="State_Master.aspx?State_ID={0}" />
                                 
                                   
                                 
                                   
                                 
                                    <asp:CommandField ShowDeleteButton="True" />
                                 
                                   
                                 
                                   
                                 
                                </Columns>
                                <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                                <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                                <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                                <RowStyle BackColor="White" ForeColor="#003399" />
                                <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                            </asp:GridView>
                        </DIV>
</td>
</tr>
<tr>
<td height="15"></td>
</tr>
<tr>

</tr>
</table>

.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;
using System.Data.SqlClient;
using System.Data;
using System.Data.SqlClient;
public partial class State_Master : System.Web.UI.Page
{
   // SqlConnection con = new SqlConnection("Data Source=KULDEEP-PC;Initial Catalog=ijcpnew;Integrated Security=True");

    State sdal = new State();

    protected void Page_Load(object sender, EventArgs e)
    {
     
        if (!Page.IsPostBack)
        {
            show_State_Detail();
           
            if (Request.QueryString["State_ID"] != null)
            {
                //Response.Write("mishra");
                hdn_Supdate.Value = Request.QueryString["State_ID"].ToString();
                Stateupdate(Convert.ToInt32(hdn_Supdate.Value));
             
            }
            else
            {
             
                Response.Write("");
            }
        }
    }
   
     public void Stateupdate(int sid)
    {

      DataTable sdt= sdal.Displaystatedetail(sid);
      if (sdt.Rows.Count > 0)
      {
      txt_SName.Text = sdt.Rows[0]["State_Name"].ToString();
       txt_SDesc.Text = sdt.Rows[0]["State_Desc"].ToString();
       //btn_update.Visible =true;
       btn_update.Enabled = true;
       btn_update.Focus();
         
      }
    }

    protected void btn_Add_Click(object sender, EventArgs e)
    {
        Add();
        show_State_Detail();
    }
    public void Add()
    {

        sdal.Insertstate(Convert.ToInt32(hdn_Sid.Value), txt_SName.Text, txt_SDesc.Text);
    }

    public void show_State_Detail()
    {
        string connstr = Conaction.GetConnString();
        SqlConnection con = new SqlConnection(connstr);
        SqlDataAdapter adpsta_Detail = new SqlDataAdapter("select * from State_MASTER", con);
       
        DataSet ds = new DataSet();
        adpsta_Detail.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            Gridstate.DataSource = ds;
            Gridstate.DataBind();
        }
        else
        {

            Gridstate.DataSource = null;
            Gridstate.DataBind();

        }
    }
   public void Reset()
    {

        txt_SName.Text = "";
        txt_SDesc.Text = "";

    }

    protected void btn_update_Click(object sender, EventArgs e)
    {
       
        int msg = sdal.Update(Convert.ToInt32(hdn_Supdate.Value), txt_SName.Text, txt_SDesc.Text);
        if (msg > 0)
        {
            show_State_Detail();
            Reset();
            Response.Write("");
           
        }
        else
        {

            Response.Write("kuldeep");

        }
       
    }
 
   
 
    protected void Gridstate_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Gridstate.PageIndex = e.NewPageIndex;
        show_State_Detail();
    }
    protected void Gridstate_SelectedIndexChanging(object sender, EventArgs e)
    {
    show_State_Detail();
    }
    protected void Gridstate_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string connstr = Conaction.GetConnString();
        SqlConnection con = new SqlConnection(connstr);
        con.Open();//dg_Customer_RowDeleting
        string ID = ((Label)(Gridstate.Rows[e.RowIndex].FindControl("ID"))).Text;

        SqlCommand cmd = new SqlCommand("Delete from STATE_MASTER where State_ID='" + ID + "'", con);

        cmd.ExecuteNonQuery();
        con.Close();

        show_State_Detail();
    }
}

Method Details  In App-Code....................>>>>



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


public class State
{
    SqlConnection con = new SqlConnection("Data Source=KULDEEP-PC;Initial Catalog=ijcpkuldeep;Integrated Security=True");
 
public State()
{

}

   

      public void Insertstate( int hdn_Sid,string SName, string SDesc)
        {
     
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "ADD_UPDATE_STATE_MASTER";
            cmd.Parameters.AddWithValue("@State_ID", SqlDbType.Int).Value = hdn_Sid;
            cmd.Parameters.AddWithValue("@State_Name", SqlDbType.VarChar).Value = SName;
            cmd.Parameters.AddWithValue("@State_Desc", SqlDbType.VarChar).Value = SDesc;
           
      cmd.ExecuteNonQuery();


      con.Close();
       
       
    }
      public DataTable Displaystatedetail(int stateid)
      {
     
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = con;
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandText = "STATE_MASTERSELECT";
          cmd.Parameters.AddWithValue("@State_ID", SqlDbType.Int).Value = stateid;
          SqlDataAdapter adps = new SqlDataAdapter();
          adps.SelectCommand = cmd;
          DataSet dss = new DataSet();
          adps.Fill(dss);
          con.Close();
          return dss.Tables[0];

      }
      public int Update(int State_ID, string State_Name, string State_Desc)
      {
       
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = con;
          con.Open();
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandText = "ADD_UPDATE_STATE_MASTER";
          cmd.Parameters.AddWithValue("@State_ID", SqlDbType.Int).Value = State_ID;
          cmd.Parameters.AddWithValue("@State_Name", SqlDbType.VarChar).Value = State_Name;
          cmd.Parameters.AddWithValue("@State_Desc", SqlDbType.VarChar).Value = State_Desc;
         
       
   int msg=  cmd.ExecuteNonQuery();
   con.Close();
   return msg;
     
         


      }
}


Store Procedure.........>>>>>>>

USE [ijcpkuldeep]
GO
/****** Object:  StoredProcedure [dbo].[ADD_UPDATE_STATE_MASTER]    Script Date: 08/30/2014 14:19:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE  [dbo].[ADD_UPDATE_STATE_MASTER]
@State_ID int,
@State_Name varchar(50),
@State_Desc varchar(150)

AS
if exists(Select * from State_Master where State_Id=@State_ID)
BEGIN
UPDATE State_Master SET
State_Name=@State_Name,
State_Desc=@State_Desc
Where State_ID=@State_ID
END
else
BEGIN
INSERT INTO State_Master
(
State_Name,
State_Desc
)
values
(
@State_Name,
@State_Desc
)

END
Table Detail .....>>>

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[STATE_MASTER](
[State_ID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[State_Name] [varchar](50) NULL,
[State_Desc] [varchar](150) NULL,
 CONSTRAINT [PK_STATE_MASTER] PRIMARY KEY CLUSTERED
(
[State_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO




insert Data in sql database by sql helper




SqlParameter[] prm = new SqlParameter[2];
            prm[0] = new SqlParameter("@name", txtname.Text);  
           prm[1] = new SqlParameter("@result", SqlDbType.Int);
            prm[1].Direction = ParameterDirection.ReturnValue;
           SqlHelper.ExecuteNonQuery(str,CommandType.StoredProcedure,"sp_insert", prm);

         Int32 check = Convert.ToInt32(prm[1].Value);
         Convert.ToInt32(prm[1].Value);
         if (check == 1)
            {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('data is added successfully   !!');", true);
       

        }

SP
Create PROCEDURE [dbo].[sp_insert]

(
@name varchar(100)
--@result  Output
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- Insert statements for procedure here
insert into tbl_user
(
name
)
values
(
@name
)
--set @result =1
return 1

END

Read each file data from folder


using System.IO;
public partial class download : System.Web.UI.Page
{
    string filepath = "~/DataFile/";

 
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

    public string file()
    {
        SqlCommand cmd = new SqlCommand("select FileName from registation where username='" + Session["uname"].ToString() + "'", con);
        con.Open();
      string  fi_Name = cmd.ExecuteScalar().ToString();
        con.Close();
        return fi_Name;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
   

        if (Session["uname"] != null)
        {
            Label1.Text = "Welcome" + Session["uname"].ToString();

        }
        else{
            Response.Redirect("userlogin.aspx");
        }
     

        DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/DataFile/"));
        FileInfo[] fi = di.GetFiles();
        foreach (FileInfo fi2 in fi)
        {


            if (file() == fi2.Name)
            {
                Response.ContentType = "application/pdf||.doc";
                Response.WriteFile(fi2.FullName);
         
           }
        }

Code for File upload in a folder

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;
using System.IO;

public partial class Admin_Muder_Mestry : System.Web.UI.Page

{
    string filepath = "~/DataFile/";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSaveNew_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=KULDEEP-PC;Initial Catalog=mobilewebsite;Integrated security=true");
        //  con.Open();
        string filename = FileUpload1.PostedFile.FileName;

        FileInfo fi = new FileInfo(filename);
        string ext = fi.Extension;

        if (ext == ".jpeg" || ext == ".jpg" || ext == ".png" || ext==".gif")
        {
            // if (ext == ".gif")
            // {
            FileUpload1.SaveAs(Server.MapPath(filepath + filename));
            //  Response.Write("<script>alert ('FileUpload Successfully' )</script>");

            string str = filepath + filename;

            try
            {

                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_pagecontent1";
                //  cmd.Parameters.AddWithValue("@id", SqlDbType.Int).Value =0;
                cmd.Parameters.AddWithValue("@pageid", SqlDbType.Int).Value = 0;
                cmd.Parameters.AddWithValue("@pagetitle", SqlDbType.VarChar).Value = txtName.Text;
                cmd.Parameters.AddWithValue("@pagedec", SqlDbType.VarChar).Value = txtContent.Text;
                cmd.Parameters.AddWithValue("@pageimage1", SqlDbType.VarChar).Value = str;
                cmd.ExecuteNonQuery();

            }

            catch (Exception ex)
            {

                throw ex;

            }

            finally
            {
                con.Close();

            }


        }
        else {

            Response.Write("<script>alert ('please select image file' )</script>");
        }
    }

}