Monday, 18 March 2013

Definations For DML,DCL,DDL.TCL

DML

DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.
Examples: SELECT, UPDATE, INSERT statements

DDL

DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.
Examples: CREATE, ALTER, DROP statements

DCL

DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.
Examples: GRANT, REVOKE statements

TCL

TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.
Examples: COMMIT, ROLLBACK statements

Sunday, 17 March 2013

How To Generate Password Automatically

 In This article i will show how to generate password automatically:
 Step 1:
.ASPX
<%@ 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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <br />
    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Italic="True"
        Font-Names="Arial"></asp:Label>
</div>
    </form>
</body>
</html>

.CS
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Design;

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

        Label1.Text = CreateRandomPassword(8);
    }
    public static string CreateRandomPassword(int PasswordLength)
    {
        string _allowedChars = "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ";
        Random randNum = new Random();
        char[] chars = new char[PasswordLength];
        int allowedCharCount = _allowedChars.Length;
        for (int i = 0; i < PasswordLength; i++)
        {
            chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
        }
        return new string(chars);
    }
   
}

Now View On browser:

Friday, 15 March 2013

Print Square Between Stars

Print Square Between The Stars:



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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 12, i, j;
            for (i = 1; i <= n; i++)
            {
                for (j = n; j >=i ; j--)
                {
                    Console.Write("*");
                }
                for (int k = 1; k <=i-1; k++)
                {
                    Console.Write("  "); //Two Sapces.
                }
                    for (j = n; j >= i; j--)
                    {
                        Console.Write("*");
                    }
                Console.WriteLine();
            }
            for (i = 1; i <= n; i++)
            {
                for (j = 1; j <= i; j++)
                {
                    Console.Write("*");
                }
                for (int k = n-1; k >=i; k--)
                {
                    Console.Write("  "); // Two Spaces
                }
                for (j = 1; j <= i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadLine();

        }
    }
}

Sunday, 3 March 2013

How to change user role using asp.net


For this you have to fallow below steps

Step 1:
 Make one “XML File “ which contains role types. In this i took one xml file and named it as
“chengerole.xml”.
<?xml version="1.0" encoding="utf-8" ?>
<changerole>
  <roles>
    <role>admin</role>
  </roles>
  <roles>
    <role>accountent</role>
  </roles>
  <roles>
    <role>teacher</role>
  </roles>
  <roles>
    <role>student</role>
  </roles>
  <roles>
    <role>parent</role>
  </roles>
  
</changerole>


Step 2:

Create a table as
create table userstable
(
UserName  nvarchar(50) not null,
Roletype nvarchar(50) not null
)

This table values will be added while the user registration: for understanding add some values to

this table

User NameRole
srinu.munagala33@gmail.comadmin
krishnareddy4b8@gmail.comaccountent
srinu33aryan@gmail.comteacher


Step 3:

Create one stored Procedure as
CREATE PROCEDURE rolechange 
@username nvarChar(50),
@role nvarChar(50)
    AS
    update usertable set Roletype=@role where UserName=@username

Step 4:
set the sqlconnection in webconfig file.

<connectionStrings>
    <add name="mycon" connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=
|DataDirectory|\SchoolManagementSystemdatabase.mdf;Integrated 
Security=True;
User Instance=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>


Step 5:
 Create one aspx file as below

<h3>Chenge Role</h3>
    <br />
    <asp:Table runat="server" ID="tblchangerole" BorderStyle="Solid"  
Height="200px"
 Width="300px" BorderColor="Black" BorderWidth="1px" HorizontalAlign="Center" >
    <asp:TableRow runat="server" ID="row1">
    <asp:TableCell>
    UserName:
    </asp:TableCell>
    <asp:TableCell>
    <asp:DropDownList ID="DropDownList1" runat="server" Width="160px"  
AutoPostBack="true" >
    </asp:DropDownList>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow runat="server" ID="row2">
    <asp:TableCell>
    Change Role:
    </asp:TableCell>
    <asp:TableCell>
    <asp:DropDownList runat="server" ID="drdprolechange" Width="160px" 
 AutoPostBack
 ="true">
    </asp:DropDownList>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow runat="server" ID="row3">
    
    <asp:TableCell>
    
    </asp:TableCell>
    <asp:TableCell>
    <asp:Button ID="Button1" runat="server" Text="Change Role"  OnClick=
"Button1_Click"/>
    
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>
    
   
    
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    
Step 6:
Code Behind 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;
using System.Xml;

namespace SchoolManagementSystem.Admin
{
    public partial class changerole : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            intiatepage();
            
            usernamebind();
            Bindrolestodropdownlist();
            Page.Header.Title = "Changerole";
            if (!IsPostBack)
            {

                if (Session["adminALoginId"] == null)
                {

                    Response.Redirect(@"~\Admin\Adminlogin.aspx");
                }

                else
                {

                    Response.ClearHeaders();

 Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, 
must-revalidate");



                }

            }
            
        }

        public void intiatepage()
        {
            
        }

        public void Bindrolestodropdownlist()
        {
            if (!IsPostBack)
            {
                XmlReader xmrd = XmlReader.Create(Server.MapPath(@"~\chengerole.
xml"));
                DataSet dt = new DataSet();
                dt.ReadXml(xmrd);
                xmrd.Close();
                drdprolechange.DataValueField = "role";
                drdprolechange.DataTextField = "role";
                drdprolechange.DataSource = dt;
                drdprolechange.DataBind();


            }

        }

        public void usernamebind()
        {
            if (!IsPostBack)
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.
ConnectionStrings["mycon"].ConnectionString);
                con.Open();
                SqlCommand cmm = new SqlCommand("select * from usertable", con);
                SqlDataAdapter adp = new SqlDataAdapter(cmm);
                DataSet dt = new DataSet();
                adp.Fill(dt);
                DropDownList1.DataTextField = dt.Tables[0].Columns["UserName"].
ToString();
                DropDownList1.DataValueField = dt.Tables[0].Columns["UserName"].
ToString();

                DropDownList1.DataSource = dt.Tables[0];
                
                
                DropDownList1.DataBind();
                con.Close();
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection(ConfigurationManager.
ConnectionStrings["mycon"].ConnectionString);
            cnn.Open();
            SqlCommand cmm = new SqlCommand("rolechange", cnn);
            cmm.CommandType = CommandType.StoredProcedure;
            cmm.Parameters.Add("@username", SqlDbType.NVarChar).Value = 
DropDownList1.SelectedValue.ToString();
            cmm.Parameters.Add("@role", SqlDbType.NVarChar).Value = 
drdprolechange.SelectedValue.ToString();
            cmm.ExecuteNonQuery();
            Label1.Text = "sucessfull";
            cnn.Close();
        }

       

    }
}