Friday, 18 December 2015

Javascript Event( On Button Click)

JavaScript Example :-

Show POP-UP Message On Button Click


Event :- On Button Click 


Message :- "Hello World" 

Source Code:-
--------------------------------------------------------
<!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 type="text/javascript">
        function myFunction() {
            alert("Hello World");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
   <h1>Javascript Example</h1>
   <p>Click On Button </p>
    <button onclick="myFunction()">
        Try it</button>
    <p id="demo">
    </p>
    </form>
</body>
</html>
--------------------------------------------------------
See Image :- 




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



Example of using LINQ to SQL Database connection in Asp.Net

Example of using LINQ to SQL Database connection in Asp.Net

Step-1 :- Design Page like this



Source Code :-  
---------------------------------------

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>On Click Events</title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="Main">
        <div>
            <table style="width:60%">
                <tr>
                    <td>
                        NAME
                    </td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Company
                    </td>
                    <td>
                        <asp:TextBox ID="txtCompany" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        City
                    </td>
                    <td>
                        <asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                <td></td><td><asp:Button ID="btnsave" Text="save" runat="server"
                        onclick="btnsave_Click" /></td>
                </tr>
                <tr>
                <td></td><td>
                    <asp:Label ID="lblmsg" runat="server" Text="msg" Visible="false"></asp:Label></td>
                </tr>
            </table>
        </div>
        <div>
        <p>Show the Data</p>
            <table style="width:100%">
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:GridView ID="grv1" runat="server">
                        </asp:GridView>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </div>
        <div id="footer">
            <p style="text-align:left">
                @ Design By Dot Net By Vickypedia</p>
        </div>
    </div>
    </form>
</body>
</html>

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

Step-2 :- Create Table "tblEmp"

Source Code :-  
---------------------------------------

Create Table tblEmp
(
    ID int identity(1,1) primary key,
    Name varchar(50),
    Company varchar(50),
    City varchar(50),
)

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

Step-3 :-  Add DBML Class in Application



Step-4 :- After then drag table "tblEmp" on DBML Class





Step-5 :-then write code for the Button "btnSave" 
              and GridView  "grv1"

Source Code :-  
---------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JavaScriprt_Examples
{
    public partial class firstPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ShowGrid();
            }
        }
        EmpDataBaseDataContext _eDBobj = new EmpDataBaseDataContext();

        protected void btnsave_Click(object sender, EventArgs e)
        {
            tblEmp tblEmpObj = new tblEmp();
            tblEmpObj.Name = txtName.Text;
            tblEmpObj.Company = txtCompany.Text;
            tblEmpObj.City = txtCity.Text;

            _eDBobj.tblEmps.InsertOnSubmit(tblEmpObj);
            _eDBobj.SubmitChanges();
            lblmsg.Visible = true;
           lblmsg.Text = "Add Successfully";
           clearform();
       
        }

        protected void clearform()
        {
            txtName.Text = "";
            txtCompany.Text = "";
            txtCity.Text = "";
        }


        protected void ShowGrid()
        {
            var v = from m in _eDBobj.tblEmps select m;
            grv1.DataSource = v;
            grv1.DataBind();
        }
    }
}
---------------------------------------

Step-6 :- Run the Application 







Thursday, 17 December 2015

hello world program in C#

Hello World -- Your First Program in Console Application



Use Console Application
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, world!");
            Console.ReadLine();
        }
    }
}

Monday, 14 December 2015

Function in SQL with Example

Function in SQL with Example

In SQL function is a Stored Program that you can pass parameters into and returns a value. 

A function must always return a value & but a procedure may or may not return a value.

Example :- (Return a single value from a Customer Table.)
------------------------------------------------
Create table Customer
 (
   SrNo  int identity(1,1) primary key,
   Name Varchar(50),
   Age  varchar(50),
   ContactNo varchar(50)
)
------------------------------------------------



Create Function 
----------------------------------------------

Create FUNCTION FUN1
(
-- Add the parameters for the function here
@id int
)
returns varchar(50)
as
BEGIN

-- Declare the return variable here
DECLARE @Name varchar(50)

-- Add the T-SQL statements to compute the return value here
SELECT @name=Name from Customer WHERE SrNo= @id

-- Return the result of the function
Return  @name


END
----------------------------------------------


Execute Function
----------------------------------------------
select dbo.fun1(1)
----------------------------------------------

Output/Result :-













Sunday, 13 December 2015

Create Button at Run time on button click by Java Script

Create Button at Run time on button click by Java Script

Source Code :-

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <p> Click the button to make a BUTTON element with text.</p>
    <button onclick="myFunction()">
        Try it</button>
    <script type="text/javascript">
        function myFunction() {
            var btn = document.createElement("BUTTON");
            var btn1 = document.createTextNode("CLICK Here");
            btn.appendChild(btn1);
            document.body.appendChild(btn);
        }
    </script>
</body>
</html>

OutPut :-















Sunday, 6 December 2015

Ternary Operator in C#

Ternary Operator in C#

Ternary operator:-
The Ternary operator is not a type of conditional statement but it is also used to check the conditions. It returns only one value based on conditions. Use the ternary operator to check many values in a single line of coding.

Syntax:-

Variable = condition ? True Part : False Part;





Conditional Operator:-
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator.

Syntax:-

Variable = condition ? first_expression : second_expression;


Source Code :-

static void Main(string[] args)   
{  
    int a, b, Value;  
    a = 100;  
    b = 50;  
    Value = a > b ? a : b ;  
    Console.WriteLine("Greater Value:" + Value);  
    Console.Read();  
} 

Output:-
      Greater Value:100          





Thursday, 26 November 2015

Continue and Break Statement in C# (Console Application)

Continue and Break Statement in C# (Console Application)

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

Difference b/w Continue and Break statement :- 

Continue statement :- A Continue statement jumps out of the current loop condition and jumps back to the starting of the loop code.

Break statement :- A Break statement breaks out of the loop at the current point or we can say that it terminates the loop condition.

----------------------------------------------------------------------------------------------------------------------------------
Source Code :- 
-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Continue_Break_Prog
{
    class Program
    {
        static void Main(string[] args)
        {
             int x;
             for (x = 0; x <= 10; x++)
          {
              if (x == 5)                             
                  continue;

              if (x == 8)              
                  break;
              Console.WriteLine("Number =" + x);            
          } 
          Console.ReadLine();              
        }
    }
}
-
Result :- 
          Number = 0
          Number = 1
          Number = 2
          Number = 3
          Number = 4
          Number = 6
          Number = 7
-----------------------------------------------------------------------------------------------------------------------------------

Thursday, 29 October 2015

Bubble Sorting in C# .Net

Bubble Sorting in C# .Net


  1. Open Visual Studio from Start - All programs - Microsoft Visual Studio.
  2. Then go to to "File" - "New" - "Project..." then select Visual C# - Windows - Console application. 

#_Code
.......................................................................................................................................................................................................................................
static void Main(string[] args)
        {
            int[] a = { 23, 32, 15, 24, 14 };  
            int t;
            for (int p = 0; p <= a.Length - 2; p++)
            {
                for (int i = 0; i <= a.Length - 2; i++)
                {
                    if (a[i] > a[i + 1])
                    {
                        t = a[i + 1];
                        a[i + 1] = a[i];
                        a[i] = t;
                    }
                }
            }
            Console.WriteLine("Simple Bubble Sort in C#");
            Console.WriteLine("The Sorted array");
            foreach (int aa in a)                         
                Console.Write(aa + " ");
            Console.Read();

        }
....................................................................................................................................................................................................................................
Unsorted Elements:-23, 32, 15, 24, 14

Sorted Elements :- 14, 15, 23, 24, 32






Friday, 23 October 2015

Stored Procedures in Sql

Stored Procedures in Sql

"A Stored Procedures is a group of SQL Statements that has been Created and Stored in the database."

............................................................................................................

Advantage :-

  • Better performance
  • Less Traffic
  • Security
  • Integrity
  • Code-Reuseblity

Disadvantage :-

  • Work with Same Database
............................................................................................................
Design a database like this image :-

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

Create a Table "Student"

Create table Student         (      RollNo int primary key,      Name nvarchar(50),      MobileNo nvarchar(50),      dob nvarchar(50)       )
-------------------------------------------------------------------------------------------------------

Create a Stored Procedures..........................

A Single Stored Procedures for multiple Query Insert,Update,Delete, & Select .. i.e. SP_Query

-------------------------------------------------------------------------------------------------------------------------
Create proc SP_Query 
      @op nvarchar(50)='g',
      @RollNo int=0,
      @Name nvarchar(50)=null,
      @MobileNo nvarchar(50)=null,
      @dob nvarchar(50)=''
as
begin
      if @op='insert'
begin
      insert into Student values(@RollNo,@Name,@MobileNo,@dob)
end
      if @op='update'
begin
      update Student set 
                 Name=@Name,
                 MobileNo=@MobileNo,
                 dob=@dob
       where RollNo=@RollNo
end
       if @op='delete'
begin
       delete from Student where RollNo=@RollNo
end
       if @op='select'
begin
        select * from Student where RollNo=@RollNo
end
else
begin
        select * from Student
end

end
--------------------------------------------------------------------------------------------------------------------------

Execute a Stored Procedures..........................

1.  executing procedure for insert the data in Student table

exec SP_Query  'insert',3,'Mr. VICKY','09654388184','02-03-1993'


2executing  procedure for updating data in Student table

  exec SP_Query  'update',2,'Mr. Vijay','08826439190','11-Oct-1993'


3. executing  procedure for select data in Student table

    exec SP_Query  'select',1

4. executing  procedure for delete data in Student table  


   exec SP_Query  'delete',4

5. executing  default procedure for  Student table  

      exec SP_Query 


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

Factorial of a Number

Recently Viewed