Monday 27 February 2017

how to change table name in SQL server

 Rename table in SQL server

Syntax:
Sp_ rename 'oldtablename','newtablename';

Example:
Sp_ rename 'emp','employee';


Friday 24 February 2017

code for upload files in folder using asp.net

Hi fiends....please follow the step by step procedure:
Hi friends this is Ravi Kumar, here i have given you the procedure and code to upload a file into a folder using asp.net. It is very easy please follow the process.
source code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="uploads.aspx.cs" Inherits="uploads" %>

<!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:FileUpload ID="FileUpload1" runat="server" />
        <br />
        <br />
        <br />
&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="fileupload" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="lblmessage"></asp:Label>
    
    </div>
    </form>
</body>
</html>

 design screen shot:






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

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        FileUpload1.SaveAs(Server.MapPath("~/uploads/" + FileUpload1.FileName));
        Label1.Text = "file uploaded successfully";
    }

}

output screenshot:





Hi friends thanks for coming

If you have any doubts or problems please comment below ill definitely give you reply


Ravi Kumar
9505216182
Hyderabad
India.


To get more clarity please watch this video.


Wednesday 22 February 2017

code for registration form in dotnet using stored procedures

Registration form in dotnet using stored procedure

Hi friends here I'm giving step by step procedure to insert data into registration form using stored procedures in dotnet
step1:  create a table 
step2:  create a stored procedure
step3:  set web.config file
step4:  design registration form in visual studio 
step5:  write code
step6:debugging and result

Sql Code for Stored Procedure to insert data into table

USE [ravi]
GO
/****** Object:  StoredProcedure [dbo].[sp_insertintoregiser]    Script Date: 02/23/2017 12:03:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sp_insertintoregiser]
@name varchar(20),
@username varchar(20),
@password varchar(20),
@phone bigint
as begin
insert into register(name,username,password,phone)values(@name,@username,@password,@phone)

end


web.config file:

<configuration>
<connectionStrings>
<add name="dbcs" connectionString="data source=hp-PC;database=ravi;integrated security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Source Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>

<!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>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            color: #009933;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style2">
    
        <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        Registration from</strong></div>
    <table class="style1">
        <tr>
            <td>
                name</td>
            <td>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                username</td>
            <td>
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                password</td>
            <td>
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                phone</td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:Label ID="Label1" runat="server" Text="lblmessage"></asp:Label>
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    </form>
</body>

</html>

Screenshot: registration form






Business logic code:

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.Configuration;

public partial class register : System.Web.UI.Page
{
    string constr = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        using (SqlConnection con = new SqlConnection(constr))
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "sp_insertintoregiser";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBox1.Text.Trim();
            cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = TextBox2.Text.Trim();
            cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = TextBox3.Text.Trim();
            cmd.Parameters.Add("@phone", SqlDbType.VarChar).Value = TextBox4.Text.Trim();
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            Label1.Text = "data inserted successfully";

        }
    }
}

Result/output screenshot:

Thank you friends...... if you have any doubts please comment below
Ravi Kumar
9505216182
Hyderabad
India.


Here you can watch the youtube video to understand clearly



Tuesday 21 February 2017

stars print in traingle shape in c# using for loop

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

namespace ConsoleApplication29
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("print stars in traingle shape");
         int val = 5;
         int i, j, k ;
         for (i = 1; i <= val; i++)
         {
            for (j = 1; j <= val-i; j++)
            {
               // Console.Write("");
            }
            for (k = 1; k <= i; k++)
            {
               Console.Write("*");
            }
            Console.WriteLine("");
         }
         Console.ReadLine();

        }
    }
}

output screenshot:







print traingle shape characters in c#

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

namespace ConsoleApplication29
{
    class Program
    {
        static void Main(string[] args)
        {
            char ch = 'A';
            for (int i = 1; i < 5; i++)
            {
                for(int j=1;j<=i;j++)
                {
                    Console.Write(ch + " ");
                    ch++;

                }
                Console.WriteLine();
            }
        }
    }

}

output screenshot:



printing numbers using foreach in c#

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

namespace ConsoleApplication51
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intarray = { 1, 2, 3, 4, 5, 6 };

            foreach (int i in intarray)
            {
                Console.WriteLine(i);
            }

            Console.ReadLine();
        }
    }

}

output screenshot:

reverse string example program in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication50
{
    class Program
    {
        static void Main(string[] args)
        {

            string Str, Revstr = "";
            Console.Write("Enter A String : ");
            Str = Console.ReadLine();

            for (int i = Str.Length - 1; i >= 0; i--)
            {

                Revstr = Revstr + Str[i];
            }

            Console.WriteLine("Reverse  String  Is  {0}", Revstr);
            Console.ReadLine();

        }
    }
}

output screenshot:






perfect number or not example program in c#

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

namespace ConsoleApplication89
{
    class Program
    {
        static void Main(string[] args)
        {
            int number, sum = 0, n;
            Console.Write("enter the Number:");
            number = int.Parse(Console.ReadLine());
            n = number;
            for (int i = 1; i < number; i++)
            {
                if (number % i == 0)
                {
                    sum = sum + i;
                }
            }
            if (sum == n)
            {
                Console.WriteLine("\n Entered number is a perfect number");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("\n Entered number is not a perfect number");
                Console.ReadLine();
            }
        }
    }
}

output screenshot:




abstract class example program in c#


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

namespace ConsoleApplication16
{
    public abstract class A
    {
        public abstract void show(); //abstract method with method declaraion
    }

    public class B:A
    {

        public override void show()  //method implementation with override keyword
        {
            Console.WriteLine("abstratct class and abstract method");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            B b1 = new B();
            b1.show();
        }
    }

}

output screenshot:







interface example program in c#

Interface sample program in c#

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

namespace ConsoleApplication15
{
    interface a
    {
        void print();
    }
    public class b : a
    {
        public void print()
        {
            Console.WriteLine("interface definition");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            b B = new b();
            B.print();
        }
    }
}

output screeshot:





inheritance example program in c#

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

namespace ConsoleApplication14
{
    public class baseclass
    {
        public baseclass()
        {
            Console.WriteLine("iam base class constructor");
        }
        public void print()
        {
            Console.WriteLine(" iam a parent class");
        }
    }
    public class deriverdclass : baseclass
    {
        public deriverdclass()
        {
            Console.WriteLine("iam derived class constructor");

        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            deriverdclass d = new deriverdclass();
            d.print();
        }
    }

}

output screenshot:







method overloading example program in c#

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

namespace ConsoleApplication13
{
    public class a
    {
        public void print(int x, int y)
        {
            Console.WriteLine("x value is"+x);
            Console.WriteLine("Y value is"+y);
        }
        public void print(string name, string add)
        {
            Console.WriteLine("my name is "+name);
            Console.WriteLine("my address is " + add);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            a A = new a();
            A.print(10, 20);
            A.print("ravi", "hyd");
            Console.ReadLine();
        }
    }

}

sorting in c#

frequently asking logical program in interviews for dotnet fresher
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace sorting
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList al = new ArrayList();
            Console.WriteLine("adding some numbers");
            al.Add(78);
            al.Add(45);
            al.Add(33);
            al.Add(90);
            al.Add(40);
            al.Add(89);
            Console.WriteLine("capacity:{0}", al.Capacity);
            Console.WriteLine("count:{0}", al.Count);
            Console.WriteLine("content:");
            foreach (int i in al)
            {
                Console.Write(i + " ");

            }
            Console.WriteLine();
            Console.Write("sorted content:");
            al.Sort();
            foreach (int i in al)
            {
                Console.Write(i + " ");

            }
            Console.WriteLine();
            Console.ReadKey();
        }
    }
}

outpuscreen:





method overriding example in c#

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

namespace ConsoleApplication34
{
    public class bc
    {
        public virtual void display()
        {
            Console.WriteLine("iam virtual method");
        }
    }
    public class dc : bc
    {
        public override void display()
        {
            Console.WriteLine("iam override method");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            bc b;
            b = new bc();
            b.display();

            b = new dc();
            b.display();

        }
    }
}

Output screen: