Wednesday, 19 February 2014

How to Generate sample Excel file in C#

ASP.Net

<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button runat="server" ID="btnExcel" Text="Generate Excel" OnClick="btnExcel_Click" />
    </div>
    </form>
</body>



Backend Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using Microsoft.Office.Interop.Excel;

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

        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            GenerateExcel();
        }

        #region GenerateExcel
        public void GenerateExcel()
        {
            Application oXL = new Application();
            Workbook WB = null;
            Worksheet WS = null;
            Range oRng;

            oXL.Visible = true;
            // creating workbook
            //--------------------
            WB = (Workbook)(oXL.Workbooks.Add(Missing.Value));

            //Create work sheet
            WS = (Worksheet)(WB.ActiveSheet);

            //save the Excel File
            // -----------------------
            WB.SaveAs(@"D:\Excelfiles\Srinivas5", XlFileFormat.xlWorkbookDefault);

            // F:\Desktop is the file path
            // srinivas is the file name  

            //oXL.UserControl = true;


        }
        #endregion
    }
}




Sunday, 8 December 2013

What is smart navigation?

What is smart navigation? 
The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed.

Wednesday, 6 November 2013

Parameters in Procedure and Functions


How to pass parameters to Procedures and Functions in PL/SQL?

In PL/SQL, we can pass parameters to procedures and functions in three ways.
1) IN type parameter: These types of parameters are used to send values to stored procedures.
2) OUT type parameter: These types of parameters are used to get values from stored procedures. This is similar to a return type in functions.
3) IN OUT parameter: These types of parameters are used to send values and get values from stored procedures.
NOTE: If a parameter is not explicitly defined a parameter type, then by default it is an IN type parameter.



Wednesday, 21 August 2013

How to create menu dynamically in Asp.Net Using Jquery.

In this article i will explain how to create a menu dynamically using jquery. The menu will create after click event of a button.

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

<!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>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="htmltabs">
    </div>
    <style type="text/css">
        ul#tab
        {
            margin: 0;
            padding-left: 10px;
            list-style-type: none;
            background-image: url[ 'http://www.galaxyfinishingschool.com/images/coursepic-dotnet.jpg' ];
        }
        ul#tab li
        {
            display: inline;
            padding-left: 10px;
            text-decoration: none;
        }
        a
        {
            text-decoration: none;
            background-color: Gray;
            font-size: 20px;
            color: White;
        }
    </style>
    <script type="text/jscript">
        $(document).ready(function () {
            $("#btnTest").click(function () {
                var str1 = '<span>srinu</span>';
                var str = '<ul id="tab"><li ><a href="http://dotnettutorialblog.blogspot.in/">Dot Net Blog</a></li><li ><a href="https://www.google.co.in/" >GooGle</a></li><li ><a href="https://www.yahoo.com/" >Yahoo</a></ul>';
                $("#htmltabs").html(str);
                $("#btnTest").css("display", "none");

            });
        });
    </script>
    <input type="button" id="btnTest" value="Get Menu" />
    </form>
</body>
</html>

Thursday, 15 August 2013

How to Replace substring in a string.

 

Here i will give an example how to replace a substring in a string. For example you want to change email address in employee details table. 

In below example i am replacing  EmailId  from “@gmail.com” to ‘”@yahoo.com” in Employee Table .

-- Exmple 01.

declare @txt1 varchar(50)
set @txt1 = 'srinu.munagala33@gmail.com'
-- Here iam replacing @gmail.com to @yahoo.com
set @txt1 = REPLACE(@txt1, '@gmail.com', '@yahoo.com')

select @txt1
-- out put
-- srinu.munagala33@yahoo.com
-- Exmple 2.
/*
You can also update employee emailid in employee table.
*/

-- before EmailID = srinu.munagala33@gmail.com

update EmployeeDetals
set EmailID = REPLACE(EmailID, '@gmail.com', '@yahoo.com')
where EmployeeCode = 3151

-- After updating EmailID = srinu.munagala33@yahoo.com

Wednesday, 10 July 2013

How to Execute C# Program using command prompt

 

 

Open Notepad

Write a sample program

 

image

 

Write bellow code in notepad and save as Test.cs

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter N number");
            int n = Convert.ToInt32(Console.ReadLine());
            int i = 0, sum=0;
            for (i = 0; i <= n; i++)
            {
                sum = sum + i;
            }
            Console.WriteLine(sum);
            Console.ReadLine();

        }
    }
}

save this file in C Drive.

Next open Visula Studio Command prompt.

set the directory in Visual studio Command Prompt

 

image

 

now enter

C:\>CSC Test.cs

image

Enter

image

Enter N

3

Then the result

0+1+2+3= 6

image

Tuesday, 9 July 2013

Find The sum of N numbers

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter N number");
            int n = Convert.ToInt32(Console.ReadLine());
            int i = 0, sum=0;
            for (i = 0; i <= n; i++)
            {
                sum = sum + i;
            }
            Console.WriteLine(sum);
            Console.ReadLine();

        }
    }
}