Saturday, 15 April 2017

how to rename column name in sql server

Hi friends in this article i will show you how to change/rename column name after creating table in SQL Server.
Actually it is very easy.....lets start


Rename Column Name:- 

Syntax:-  

sp_rename 'TableName.ColumnName','Column';

For suppose I had a table with name kishor in that I had 3 columns. I want to change "kname" as just "name" .


Example:-

sp_rename 'kishor.kname', 'name', 'column';

or

exec sp_rename 'kishor.kname', 'name', 'column';







In the above screenshot you can see the column name changed as "kname" to "name"

I hope you understand.
Thanks for reading. 
I will come with new concept bye.

Ravi Kumar.
Hyderabad India. 




Monday, 27 March 2017

insert and bind data in gridview using 3 tier architecture in dotnet

3tier architecture example to insert and bind data in gridview
table 







Presentation(User Interface)

Source Code for above design
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            text-align: center;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <div class="auto-style2">
            <strong>3Tier Example</strong></div>
        <table class="auto-style1">
            <tr>
                <td>Name</td>
                <td>
                    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>City</td>
                <td>
                    <asp:TextBox ID="txtcity" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Email</td>
                <td>
                    <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <asp:Button ID="btnsave" runat="server" OnClick="btnsave_Click" Text="save" />
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>
                    
                </td>
            </tr>
        </table>
    
    </div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </form>
</body>

</html>


DAL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class Class1
    {
    }
    public class ClsDataLayer
    {
        SqlConnection con = new SqlConnection("data source=ravi-PC;database='3tierexample';integrated security='true';");
        public void InsertData(string _name,String _city,String _email)
        {
            SqlDataAdapter adp = new SqlDataAdapter("insert into Usermst values('"+_name+ "','" + _city + "','" + _email + "')",con);
            DataTable dt = new DataTable();
            adp.Fill(dt);

        }
        public object SelectData()
        {
            SqlDataAdapter adp = new SqlDataAdapter("select *from Usermst", con);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            return dt;
        }
    }

}

BLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using BLL;

namespace BLL
{
    
    public class Class1
    {
    }
    public class CLSBussLayer
    {
        ClsDataLayer objDAL = new ClsDataLayer();
        public void InsertUser(String _name,String _city,string _email)
        {
            objDAL.InsertData(_name, _city, _email);
        }
        public object SelectUser()
        {
            return objDAL.SelectData();
        }
    }
}

Code for Button_Click

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnsave_Click(object sender, EventArgs e)
    {
        CLSBussLayer objBLL = new CLSBussLayer();
        objBLL.InsertUser(txtname.Text, txtcity.Text, txtemail.Text);
        GridView1.DataSource = objBLL.SelectUser();
        GridView1.DataBind();
    }
}



i will give you clear explanation
follow step by step

Tuesday, 7 March 2017

code for gridview insert update and delete

gridview insert update and delete code 





Source code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="gridview.aspx.cs" Inherits="gridview" %>

<!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:GridView ID="gv" runat="server" AutoGenerateColumns="False" 
            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="id" 
            onrowcancelingedit="gv_RowCancelingEdit" onrowdeleting="gv_RowDeleting" 
            onrowediting="gv_RowEditing" onrowupdating="gv_RowUpdating">
            <Columns>
                <asp:TemplateField HeaderText="productname">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("productname") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("productname") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="productprice">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("productprice") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("productprice") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="insert" />
&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TextBox4" runat="server" Width="73px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TextBox5" runat="server" Width="73px"></asp:TextBox>
    </form>
</body>
</html>


Code

Insert update and delete in gridview
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;

public partial class gridview : System.Web.UI.Page
{
    string constr = "data source=ravi;database=ravi;integrated security=yes";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            binddata();
        }
    }
    private void binddata()
    {
        DataTable dt = new DataTable();
        using (SqlConnection con = new SqlConnection(constr))
        {
            
            SqlDataAdapter adp = new SqlDataAdapter("select *from service", con);
            adp.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                gv.DataSource = dt;
                gv.DataBind();
            }
        }
    }

    protected void gv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gv.EditIndex = -1;
        binddata();

    }

    protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id=int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
        deleteservice(id);
        binddata();
    }

    protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gv.EditIndex = e.NewEditIndex;
    }

    protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int id = int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
        TextBox textbox2 = (TextBox)gv.Rows[e.RowIndex].FindControl("textbox2");
        TextBox textbox3 = (TextBox)gv.Rows[e.RowIndex].FindControl("textbox3");
        updateservice(id,textbox2.Text,int.Parse(textbox3.Text));
        gv.EditIndex=-1;
        binddata();
     
    }
    private void updateservice(int id,string productname,int productprice)
    {
        using (SqlConnection con = new SqlConnection(constr))
        {
            string query="update service set productname='"+productname+"',productprice="+productprice+" where id="+id+"";
            SqlCommand cmd = new SqlCommand(query, con);
            con.Open();
            cmd.ExecuteNonQuery();
        }

    }
    private void deleteservice(int id)
    {
        using (SqlConnection con = new SqlConnection(constr))
        {
            string query = "delete from service where id=" + id + "";
            SqlCommand cmd = new SqlCommand(query, con);
            con.Open();
            cmd.ExecuteNonQuery();
        }

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string productname = TextBox4.Text;
        decimal productprice =decimal.Parse(TextBox5.Text);

        using (SqlConnection con = new SqlConnection(constr))
        {
            string query="insert into service values('"+TextBox4.Text+"',"+TextBox5.Text+")";
            SqlCommand cmd = new SqlCommand(query, con);
            con.Open();
            cmd.ExecuteNonQuery();
            gv.DataBind();
            con.Close();
            binddata();
        }
    }
}

Thursday, 2 March 2017

palindrome string programme in c#

Palindrome string program in c#

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

namespace ConsoleApplication78
{
    class Program
    {
        static void Main(string[] args)
        {
            string Str, Revstr = "";
            int i;
            Console.Write("Enter A String : ");
            Str = Console.ReadLine();

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

                Revstr = Revstr + Str[i];
            }
            if (Revstr == Str)
            {

                Console.WriteLine("entered String  Is palindrome");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("entered  String  Is not palindrome ");
                Console.ReadLine();
            }
        }
    }
}
Output screenshot:


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: