Friday, 28 December 2012

How to go back to login page after session expires.

Wednesday, 26 December 2012

Write a program to ADD Two Matrix in C#

Yes here ,I am writing a program in C# to add two matrix.

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

namespace ConsoleApplication1
{
    class AddTwo_Matrix
    {
        static void Main(string[] args)
        {
            int[,] a = { { 1, 3, 4 }, { 2, 4, 7 }, { 3, 5, 6 } };
            int[,] b = { { 3, 5, 5 }, { 4, 5, 6 }, { 2, 7, 8 } };
            int[,] c = new int[3,3];
            int f = c.Length;
            int i, m = 0;
            int j = 0, n = 0;
            for (i = 0; i < 3; i++)
            {
                Console.WriteLine("");
                for (j = 0; j < 3; j++)
                {
                    Console.WriteLine(""+a[i,j]);
                }
            }
            Console.WriteLine("\n");
            for (m = 0; m < 3; m++)
            {
                Console.WriteLine("");
                for (n = 0; n < 3; n++)
                {
                    Console.WriteLine(""+b[m,n]);
                }
            }
            Console.WriteLine("\n");
            for (int k = 0; k < 3; k++)
            {
                Console.WriteLine("");
                for (int l = 0; l < 3; l++)
                {
                    Console.WriteLine(a[k,l]+b[k,l]+"\t");
                }
            }
            Console.WriteLine("yes it is Solved ,its very easy to add two matrix");
            Console.Read();

        }
    }
}

How to Find nth Salary and his id from a table in SQL server

I am writhing a query that will be helpful in finding nth salary and his id of that record.

so its very simple and very understandable.......

select ID ,salary from testing where salary in(select MIN(salary) from testing where
salary in (select top 4 salary from testing   order by salary desc))


Here, First we find the nth salary from the table in decreasing order and then we select min salary from that records means from it sub query.
and then can fetch id ,salary of the table from the sub query result as u seeing in query.
if you are unable to understand then please drop a comment at below..............
or mail me at Kushwaha.pankajkumar07@gmail.com

Tuesday, 25 December 2012

How To check Session authentication in asp.net

 I hope that it will be beneficial for everyone.....

protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtmajorhead.Text == "")
        {
            lbl_msg.Text = "User Name is required !";
        }
        else if (txtdescp.Text == "")
        {
            lbl_msg.Text = "Password is required !";
        }
        else
        {
            Parameter UserId = new Parameter(txtmajorhead.Text);
            Parameter Password = new Parameter(txtdescp.Text);
            SqlDataAdapter da = new SqlDataAdapter("select * from Login where UserID='" + UserId + "' and Password='" + Password + "'", con);
            DataSet ds = new DataSet();
            da.Fill(ds);
           
            if (ds.Tables[0].Rows.Count > 0)
            {
                Session["UserID"] = ds.Tables[0].Rows[0]["UserID"].ToString();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if ((ds.Tables[0].Rows[i]["UserID"].ToString() == txtmajorhead.Text) && (ds.Tables[0].Rows[i]["Password"].ToString() == txtdescp.Text))
                    {
                        f = 1;

                        Response.Redirect("AddCategory.aspx");
                        break;
                    }
                }
            }
            if (f == 0)
            {

                lbl_msg.Text = "UserName And Password Are Incorrect";


            }
            txtmajorhead.Focus();

        }