Monday, September 24, 2012

Ajax Control ToolKit

 

Ajax Control Toolkit has many controls and extenders. Extenders are the ones which enhance or extends the functionality of other controls. Ajax Toolkit is an open source. Anyone can download it , use it and can contribute code to it to add additional functionality.

This toolkit can be downloaded from here:

http://ajaxcontroltoolkit.codeplex.com/

It is not a part of Visual Studio , so we need to download the library(.dll file) and add it to visual studio. Ajax Control Toolkit can only be added to Visual Studio Version 2008 and above.

To add Ajax Control ToolKit to Visual Studio , Check my article on How to Install ASP.net AJAX Control ToolKit

Asp.net Ajax Control Toolkit Extenders:

These are the controls which extend the functionality of other controls. Asp.net validator’s are good examples for extenders. For example consider “RequiredFieldValidator” , it is associated with the Textbox and extends the functionality of textbox to check whether it has value or not. If it does not have value it prompts user. Likewise Ajax Control Toolkit extenders are used to enhance the functionality of other controls and change their behaviour.

ToolkitScriptManager:

As ScriptManager is used to handle script for Ajax Controls , we need to use “ToolkitScriptManager” for Ajax Toolkit Controls and extenders. It is derived from the base Script manager to handle scripts.

Saturday, September 22, 2012

Animation Extender Example - Ajax Control ToolKit

 

In this article I will illustrate how to use Animation Extender Control of Ajax Control ToolKit to generate animations in your page.

About:

We can use this extender to add some animation effects to the controls in the page. We can make the controls move around in the page using this control based on some events. The events against which we can program this animations are :

1)OnClick

2)OnMouseOver

3)OnMouseOut

4)OnHouseOver

5)OnHouseOut.

Step 1: Open New website and name it AnimationExtenderExample.

Step 2: As Animation Extender is Ajax Control , register AjaxControlTollkit in your solution by either using @register directive or adding the namespace in the web.config file.

Step 3: Add ScriptManager to the page as follows:

<ajaxToolkit:ToolkitScriptManager  ID="Sc1" runat="server"></ajaxToolkit:ToolkitScriptManager>
Step 4: Add a panel to the page. Add some controls to the panel on which animation needs to be applied.


<asp:Panel ID="AnimationPnl" runat="server" BackColor="#FFFF99" Height="50px" Width="200px">
<asp:Label ID="lblText" runat="server"
Text="PAY ATTENTION TO THIS PANEL TO SEE ANIMATIONS EFFECTS" Font-Bold="True"
ForeColor="Red"></asp:Label>
</asp:Panel>

Step 5: Create a target control on whose Click or MouseOver events Animation Extender is invoked. Here I will take a link button. we can use button also.



<asp:LinkButton ID="lnkClick" runat="server" Text="Click Me!!"></asp:LinkButton>

Step 6: Add Animation Extender Control of Ajax Control Toolkit


We can use AnimationExtender to generate various animations like fadeout , resize , change the color of control etc. In this article I will illustrate how to fadeout ,resize and change the color of panel on Click and MouseOver Events.

Resize Panel using AnimationExtender: (On MouseOver event of Link Button)


 <form id="form1" runat="server">
<div>
<ajaxToolkit:ToolkitScriptManager ID="Sc1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<asp:Panel ID="AnimationPnl" runat="server" BackColor="#FFFF99" Height="250px" Width="400px" BorderWidth="2">
<asp:Label ID="lblText" runat="server"
Text="PAY ATTENTION TO THIS PANEL TO SEE ANIMATIONS EFFECTS!!!" Font-Bold="True"
ForeColor="Red"></asp:Label>
</asp:Panel>
<br />
<br />
<asp:LinkButton ID="lnkClick" runat="server" Text="Get Mouse on Me!!"></asp:LinkButton>
<ajaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="lnkClick" >
<Animations>
<OnMouseOver>
<Resize AnimationTarget="AnimationPnl" Width="200" Height="200" Unit="px" />
</OnMouseOver>
</Animations>
</ajaxToolkit:AnimationExtender>

</div>
</form>

FadeOut panel Using AnimationExtender: (On MouseOver event of Link Button)


 <form id="form1" runat="server">
<div>
<ajaxToolkit:ToolkitScriptManager ID="Sc1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<asp:Panel ID="AnimationPnl" runat="server" BackColor="#FFFF99" Height="250px" Width="400px" BorderWidth="2">
<asp:Label ID="lblText" runat="server"
Text="PAY ATTENTION TO THIS PANEL TO SEE ANIMATIONS EFFECTS!!!" Font-Bold="True"
ForeColor="Red"></asp:Label>
</asp:Panel>
<br />
<br />
<asp:LinkButton ID="lnkClick" runat="server" Text="Get Mouse on Me!!"></asp:LinkButton>
<ajaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="lnkClick" >
<Animations>
<OnMouseOver>
<FadeOut AnimationTarget="AnimationPnl" Duration="2" Fps="20" />

</OnMouseOver>
</Animations>
</ajaxToolkit:AnimationExtender>

</div>
</form>

Changing the color of Panel using AnimationExtender: (On Click Event of Link Button)


<form id="form1" runat="server">
<div>
<ajaxToolkit:ToolkitScriptManager ID="Sc1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<asp:Panel ID="AnimationPnl" runat="server" BackColor="#FFFF99" Height="250px" Width="400px" BorderWidth="2">
<asp:Label ID="lblText" runat="server"
Text="PAY ATTENTION TO THIS PANEL TO SEE ANIMATIONS EFFECTS!!!" Font-Bold="True"
ForeColor="Red"></asp:Label>
</asp:Panel>
<br />
<br />
<asp:LinkButton ID="lnkClick" runat="server" Text="Click Me!!"></asp:LinkButton>
<ajaxToolkit:AnimationExtender ID="AnEx1" runat="server" TargetControlID="lnkClick" >
<Animations>
<OnClick>
<Sequence>
<Color
AnimationTarget="AnimationPnl"
Duration="3000"
Property="style"
PropertyKey="backgroundColor"
StartValue="#CE0E3F"
EndValue="#FFFFFF" />
</Sequence>
</OnClick>
</Animations>
</ajaxToolkit:AnimationExtender>

</div>
</form>

Friday, September 21, 2012

EDIT and UPDATE GridView using AJAX MODALPOPUPEXTENDER

In this article I will explain how to edit and update data in gridview using AJAX ModalPopupExtender.

ASPX Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
      
       .modalBackground
        {
            background-color: Gray;
            filter: alpha(opacity=50);
            opacity: 0.7;
        }
        .pnlBackGround
        {
            position: fixed;
            top: 10%;
            left: 10px;
            width: 300px;
            height: 125px;
            text-align: center;
            background-color: White;
            border: solid 3px black;
        }
    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblTitle" runat="server" Text="BINDING DEPARTMENT DETAILS FOR EDIT AND UPDATE OPERATIONS USING MODALPOPUPEXTENDER CONTROL OF AJAX CONTROL TOOLKIT"
            ForeColor="Red"></asp:Label>
        <br />
        <br />
        <asp:ScriptManager ID="Sc1" runat="server">
        </asp:ScriptManager>
        <asp:GridView ID="gvDeptDtls" runat="server" AutoGenerateColumns="false" DataKeyNames="DeptCode"
            OnRowCommand="gvDeptDtls_OnRowCommand" BackColor="#FFFFCC" ForeColor="Black">
            <HeaderStyle BackColor="Chocolate" Font-Bold="true" />
            <Columns>
                <asp:ButtonField HeaderText="Edit" CommandName="EditRow" Text="Edit" ItemStyle-ForeColor="Blue" />
                <asp:TemplateField HeaderText="Department Code">
                    <ItemTemplate>
                        <asp:Label ID="lblDeptCode" runat="server" Text='<%# Bind("DeptCode")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Department Name">
                    <ItemTemplate>
                        <asp:Label ID="lblDeptName" runat="server" Text='<%# Bind("DeptName")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Department Description">
                    <ItemTemplate>
                        <asp:Label ID="lblDeptDescp" runat="server" Text='<%# Bind("DeptDescp")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:Button ID="btnShowPopUp" runat="server" Style="display: none" />
        <br />
        <br />
        <asp:Panel ID="Pn1" runat="server">
            <asp:GridView ID="gvUpdate" runat="server" AutoGenerateColumns="false" BackColor="#FFFFCC"
                ForeColor="Black" DataKeyNames="DeptCode">
                <HeaderStyle BackColor="Chocolate" Font-Bold="true" />
                <Columns>
                    <asp:TemplateField HeaderText="Department Code" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblDeptCode" runat="server" Text='<%# Bind("DeptCode") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Department Name" ItemStyle-HorizontalAlign="Center"
                        ItemStyle-VerticalAlign="Middle">
                        <ItemTemplate>
                            <asp:TextBox ID="txtDeptName" runat="server" Text='<%# Bind("DeptName") %>' Width="80px"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Department Description" ItemStyle-HorizontalAlign="Center"
                        ItemStyle-VerticalAlign="Middle">
                        <ItemTemplate>
                            <asp:TextBox ID="txtDeptDescp" runat="server" Text='<%# Bind("DeptDescp") %>' Width="100px"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <br />
            <br />
            <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
        </asp:Panel>
        <ajaxToolkit:ModalPopupExtender ID="Mdp1" runat="server" TargetControlID="btnShowPopUp"
            PopupControlID="Pn1" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
        </ajaxToolkit:ModalPopupExtender>
    </div>
    </form>
</body>
</html>
Code Behind:

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

public partial class Forum_Topics_ModalPopup_editupdate_griddtls : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    protected DataTable CreateDataTable()
    {
        DataTable Dt = new DataTable();
        Dt.Columns.Add("DeptCode", typeof(Int16));
        Dt.Columns.Add("DeptName", typeof(String));
        Dt.Columns.Add("DeptDescp", typeof(string));

        return Dt;
    }
    protected void BindGrid()
    {
        /*JUST CREATE TWO ROWS*/
        DataTable dtDept = CreateDataTable();
        DataRow dr = dtDept.NewRow();
        dr["DeptCode"] = 1;
        dr["DeptName"] = "Science";
        dr["DeptDescp"] = "Science Dept";
        dtDept.Rows.Add(dr);
        DataRow dr1 = dtDept.NewRow();
        dr1["DeptCode"] = 2;
        dr1["DeptName"] = "Maths";
        dr1["DeptDescp"] = "Mathematics Dept";

        dtDept.Rows.Add(dr1);

        gvDeptDtls.DataSource = dtDept;
        gvDeptDtls.DataBind();

    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        /*FETCH UPDATED VALUES OF THAT PARTICULAR ROW ON GRID*/
        string DeptName, DeptDescp;
        int Dept_Code = 0;
        Dept_Code = Int32.Parse(ViewState["DeptCode"].ToString());
        Dept_Code = Int32.Parse(((Label)gvUpdate.Rows[0].FindControl("lblDeptCode")).Text);
        DeptName = ((TextBox)gvUpdate.Rows[0].FindControl("txtDeptName")).Text;
        DeptDescp = ((TextBox)gvUpdate.Rows[0].FindControl("txtDeptDescp")).Text;

        /*MODIFY ORIGINAL GRID VALUES*/
        DataTable DtUpdateGV = CreateDataTable();
        for (int i = 0; i < gvDeptDtls.Rows.Count; i++)
        {
            DataRow dr = DtUpdateGV.NewRow();
            if (Int32.Parse(((Label)gvDeptDtls.Rows[i].FindControl("lblDeptCode")).Text) == Dept_Code)
            {
                dr["DeptCode"] = Dept_Code;
                dr["DeptName"] = DeptName;
                dr["DeptDescp"] = DeptDescp;
            }
            else
            {
                dr["DeptCode"] = ((Label)gvDeptDtls.Rows[i].FindControl("lblDeptCode")).Text;
                dr["DeptName"] = ((Label)gvDeptDtls.Rows[i].FindControl("lblDeptName")).Text;
                dr["DeptDescp"] = ((Label)gvDeptDtls.Rows[i].FindControl("lblDeptDescp")).Text;

            }
            DtUpdateGV.Rows.Add(dr);
        }

        gvDeptDtls.DataSource = null;
        gvDeptDtls.DataBind();
        gvDeptDtls.DataSource = DtUpdateGV;
        gvDeptDtls.DataBind();

    }
    protected void showModalPopUp(int GridRowNo)
    {
        /*BIND GRID IN THE POP UP */
        DataTable DtUpdate = CreateDataTable();
        DataRow dr = DtUpdate.NewRow();
        dr["DeptCode"] = ((Label)gvDeptDtls.Rows[GridRowNo].FindControl("lblDeptCode")).Text;
        dr["DeptName"] = ((Label)gvDeptDtls.Rows[GridRowNo].FindControl("lblDeptName")).Text;
        dr["DeptDescp"] = ((Label)gvDeptDtls.Rows[GridRowNo].FindControl("lblDeptDescp")).Text;
        DtUpdate.Rows.Add(dr);

        gvUpdate.DataSource = DtUpdate;
        gvUpdate.DataBind();

        /*WILL SHOW THE MODALPOPUP*/
        Mdp1.Show();
    }
    protected void gvDeptDtls_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        /*WRITE CODE HERE TO OPEN MODALPOP UP ON CLICK OF EDIT LINK BUTTON IN THE GRID*/
        if (e.CommandName == "EditRow")
        {
            int rowIndex = Convert.ToInt32(e.CommandArgument);
            int DeptCode = Convert.ToInt32(gvDeptDtls.DataKeys[rowIndex].Value);
            ViewState["DeptCode"] = DeptCode;
            showModalPopUp(rowIndex);

        }
    }
}

Tuesday, September 18, 2012

Developing Widgets with ASP.NET

 

In this article i will illustrate how to create simple widget and use that widget in a web page. 

Widget:

Widgets are the small piece of code that can be embedded in any web page. Google Ads is common example for widgets that we see every day. These ads are produced by placing small piece of code( widget) in a webpage.

We can create our own widgets and make available to others or use the widgets created by others in our web pages. Widget is like a normal web page only. So it has its own post backs , click events etc. So be careful while embedding widgets in your webpage.

Here is the code for creating sample calculator widget which just calculates the sum of two numbers and outputs the result

Creating a Widget using C#.net (Sample Calculator Widget)

Aspx Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CreateaCalculatorWidget.aspx.cs" Inherits="Forum_Topics_CreateaCalculatorWidget" %>

<!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>
<asp:Label ID="lblWidget" runat="server" Text="Sample Calculator Widget" ForeColor="Red"></asp:Label>
<br />
<br />
<asp:textbox ID="txtNum1" runat="server"></asp:textbox>
<br />
+
<br />
<asp:textbox ID="txtNum2" runat="server"></asp:textbox>
<br />
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
<br />
<br />
<asp:textbox ID="txtResult" runat="server" Enabled="false"></asp:textbox>

</div>
</form>
</body>
</html>



Code Behind:

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

public partial class Forum_Topics_CreateaCalculatorWidget : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnAdd_Click(object sender, EventArgs e)
{
txtResult.Text = ( Int32.Parse(txtNum1.Text) + Int32.Parse(txtNum2.Text)).ToString();
}
}



Output:

Widget1

How to use Widgets in a Web Page:

Iframe is used to embed widgets in our web page .

Widget can be present in our local server or in the remote sever.

Specify the absolute path of widget in the “src” attribute of Iframe.

Sample code for using widget in web page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="useWidget.aspx.cs" Inherits="Forum_Topics_useWidget" %>

<!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>
<asp:Label ID="lblWidget" runat="server" Text="Using Sample Calculator Widget in my web page"
ForeColor="#3366FF"></asp:Label>
<br />
<br />
<iframe id="frm1" runat="server" src="CreateaCalculatorWidget.aspx"></iframe>
</div>
</form>
</body>
</html>




Output:


widget2

Example of ModalpopupExtender – Ajax Control

 

In this article I will illustrate how to create a ModalpopupExtender.

Its Use: ModalpopupExtender is an Ajax Control. It is used to pop up a panel. Whatever the controls you want to see in your ModalPopupExtender add it to a panel and assign this Panel Id to “TargetControlID” attribute of ModalpopupExtender.

Important attributes of this control are :

TargetControlID – to which we need to assign a Id of the Control (like button or hyperlink)

PopupControlID – assign Id of the panel to be shown in the pop up.

OkControlId – Id of Ok / Submit button control.

CancelControlId – Id of Cancel button

OnOkScript – add some java script functionality for click of Ok button

OnCancelScript - add some java script functionality for click of Cancel button.

So to use it we need to either register Ajax Control ToolKit or add namespace in Web.Config file. For adding Ajax Control Toolkit to the project or solution , check my earlier article :

http://sailajareddy-technical.blogspot.in/2012/09/how-to-install-aspnet-ajax-control.  

Aspx Code:

 <form id="form1" runat="server">
<asp:ScriptManager ID="Sc1" runat="server"></asp:ScriptManager>
SAMPLE CODE TO ILLUSTRATE MODELPOPUPEXTENDER OF AJAX CONTROL TOOLKIT
<br />
<br />
<asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" />
<br />
<br />
Text Entered in Modalpopup:
<asp:TextBox ID="txtShow" runat="server"></asp:TextBox>
<asp:Panel ID="Pn1" runat="server">
<asp:TextBox ID="txtData" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />
<asp:Button ID="btnCancel" Text ="Cancel" runat="server" />
</asp:Panel>

<ajaxToolkit:ModalPopupExtender
ID="PopUp1" runat="server"
TargetControlID="btnShow"
PopupControlID="Pn1"
CancelControlID="btnCancel">
</ajaxToolkit:ModalPopupExtender>
</form>



Code Behind:

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

public partial class Forum_Topics_ModelpopupExtender_Sample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtShow.Text = txtData.Text;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
txtShow.Text = txtData.Text;
}
}

Monday, September 17, 2012

Sample Code to insert form data into Excel using C#.net

In this article I will illustrate how to insert form data into Excel using OleDBConnection.

For example , we need to capture Product Information through a form and insert this data into Excel ,
where Product Information consists of ItemCode , ItemName and Price.

Design:

Open new project and create three textboxes to capture  ItemCode , ItemName and Price information.
Add a save button to form . Onclick of this button data will be inserted into Excel.
Next time when user enters another record , it will be appended to the data in the excel sheet.

Here is the sample code to insert data into Excel using C#.net

Note:
     Create an Excel file at the location mentioned  i.e "C:/Users/Sony/Desktop/test.xlsx"
and name the columns as ItemCode, ItemName , Price.


string con = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/Sony/Desktop/test.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES'";


Aspx Code:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditSaveLinksinGridView.aspx.cs" Inherits="Forum_Topics_EditSaveLinksinGridView" %>

<!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>Saving form data to excel</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
        <td colspan="2" style="color: #FF0000">
             <asp:Label ID="lblMsg" runat="server"></asp:Label>        
        </td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
        <td>
             ENTER ITEM CODE:
        </td>
        <td>
        <asp:textbox ID="txtItemCode" runat="server"></asp:textbox>    
        </td>
    </tr>
     <tr>
        <td>
             ENTER ITEM NAME:
        </td>
        <td>
        <asp:textbox ID="txtItemName" runat="server"></asp:textbox>
        </td>
    </tr>
    <tr>
        <td>
             ENTER PRICE:
        </td>
        <td>
        <asp:textbox ID="txtPrice" runat="server"></asp:textbox>    
        </td>
    </tr>
   <tr>
        <td colspan="2" align="center">
            <asp:Button ID="btnSave" runat="server" Text="Save to Excel" OnClick="btnSave_Click" />        
        </td>
   </tr>
    </table>
           
        
        <br />

    </div>
    </form>
</body>
</html>

Code behind(.cs file)


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;

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

    protected void Page_Load(object sender, EventArgs e)
    {
        lblMsg.Text = "";
   }
    protected DataTable MakeDataTable()
    {
        DataTable Dt = new DataTable();
        Dt.Columns.Add("ItemCode", typeof(string));
        Dt.Columns.Add("ItemName", typeof(string));
        Dt.Columns.Add("Price", typeof(string));
        return Dt;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string con = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/Sony/Desktop/test.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES'";
        OleDbConnection obj = new OleDbConnection(con);
        obj.Open();
        OleDbCommand cmd = new OleDbCommand("Insert into [Sheet1$](ItemCode , ItemName , Price) values('" + txtItemCode.Text + "','" + txtItemName.Text + "','" + txtPrice.Text + "')", obj);
        cmd.ExecuteNonQuery();
        lblMsg.Text = "RECORD IS INSERTED SUCCESSFULLY!!";
        txtItemCode.Text = txtItemName.Text = txtPrice.Text = string.Empty;
        obj.Close();
    }
}

Saturday, September 15, 2012

ENCRPT AND DECRYPT STORED PROCEDURES IN SQLSERVER 2008



To encrypt a stored procedure in sql server 2008 , use with encryption while


creating it.
if stored procedure is already created , then use it with alter statement.

Here is an example to create an encrypted stored procedure:

CREATE PROCEDURE SP_WITH_ENCRYPTION
WITH ENCRYPTION
AS
BEGIN
SELECT 'HI..THIS STORED PROCEDURE IS ENCRYPTED'
END
GO



Any user , even the user with administrative privileges can not view the text

of this procedure now. It is locked.

To decrypt a stored procedure or any other object, we have to use third party

tools.

One of such third party tool is "OPTILLECT" SQL Decryptor tool.

This tool can be downloaded from this url
http://download.cnet.com/Optillect-SQL-Decryptor/3000-10254_4-75300271.html

Using this tool, one can view the text of the encryted stored procedure or

download/save the script of that procedure at some location on to the disc.

This tool simply connects with the sql server and looks like sql server

management studio.

 one has to login with " sa" password (administrator account) to decrypt the

procedures.