Monday 27 April 2015

How to Create table in sql server ?


Create table command in sql:-

CREATE TABLE [dbo].[Tax](
      [TaxID] [int] NOT NULL,
      [TaxName] [nchar](50) NULL,
      [TaxRule] Numeric(18,2)) NULL,
      [Description] [text] NULL,
      [FinancialYear] [nvarchar](255) NULL,
      [TaxStatus] [nchar](10) NULL,
 CONSTRAINT [PK_Tax] PRIMARY KEY CLUSTERED
(
      [TaxID] ASC
)
)

Insert query in sql

Syntex
Insert into tableName(clo1,clo2,col3) Values(value1.value2,value3)

Example

INSERT INTO [dbo].[Tax] ([TaxID], [TaxName], [TaxRule], [Description], [FinancialYear], [TaxStatus])
 VALUES (1, 'Service Tax',CAST(2.50 AS Numeric(18, 2)),'As par Govt. of India', 'March 2012-13', 'Active')
INSERT INTO [dbo].[Tax] ([TaxID], [TaxName], [TaxRule], [Description], [FinancialYear], [TaxStatus])
 VALUES (2, 'Transportation Tax',CAST(12.50 AS Numeric(18, 2)),'As par Govt. of India', 'March 2012-13', 'InActive')
INSERT INTO [dbo].[Tax] ([TaxID], [TaxName], [TaxRule], [Description], [FinancialYear], [TaxStatus])
 VALUES (3, 'VAT',CAST(12.50 AS Numeric(18, 2)),'As par Govt. of India', 'March 2012-13', 'Active')
INSERT INTO [dbo].[Tax] ([TaxID], [TaxName], [TaxRule], [Description], [FinancialYear],
 [TaxStatus])
 VALUES (4, 'sessional Tax',CAST(1.50 AS Numeric(18, 2)),'As par Govt. of India', 'March 2012-13', 'Active')

Result after runing the query















Delete query with where clause it will delete only conditional row





Saturday 25 April 2015

Transpose of a given Matrix in c# asp.net

  1. Transpose.
  2.  The transpose of a matrix is a new matrix whose rows are the columns of the original. (This makes the columns of the newmatrix the rows of the original).

  3.      Matrix A =  [1   2   

                             3   4 ]
    1. Transpose of Matrix A =  [1   3   

                                                  2   4 ]
     Source code in c#
  4. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Globalization;
    using System.Data;

    namespace ConsoleDemoApp
    {
        class MatrxTranspose
        {
            /* program to write a exception in c# */

            public static void Main(string[] args)
            {
                int row, col, i, j;
                Console.Write("Enter Number Of Rows and Columns  Of Matrices A : ");
                row = Convert.ToInt16(Console.ReadLine());
                //Console.Write("Enter Number Of Columns Of Matrices A : ");
                //col = Convert.ToInt16(Console.ReadLine());
                col = row;
                int[,] A = new int[row, col];
                Console.Write("\nEnter The Matrix A: \n");
                for (i = 0; i < row; i++)
                {
                    for (j = 0; j <  col; j++)
                    {
                        A[i, j] = Convert.ToInt16(Console.ReadLine());
                    }
                }

                
                //Console.Clear();
                Console.WriteLine("\nOriginal Matrix A : ");
                for (i = 0; i < row; i++)
                {
                    for (j = 0; j <  col; j++)
                    {
                        Console.Write(A[i, j] + "\t");

                    }
                    Console.WriteLine();
                }
               
                Console.Write("\nTranspose of Matrix A:\n");
                for (i = 0; i < row; i++)
                {
                    for (j = 0; j <  col; j++)
                    {
                        Console.Write(A[j, i] + "\t");

                    }
                    Console.WriteLine();
                }
                Console.Read();
            }
        }
    }

Output