Tuesday, 29 July 2014

Bubble Sort Using C#

Something we are calling it as sinking sort, it is simple way of sorting of repedatly steps of list to make it sort. Pass the value of list to one by one until it not swap. The way the comparison sort is similar way as bubble sort.

Bubble sort example image (from Wiki)

Find the duplicates value in Array in C#

Finding the duplicate value in array using C# code.

class Program
    {
        static void Main(string[] args)
        {
            string InuputString = "Input Array \n";
             Console.WriteLine(InuputString);

             ArrayList obj = new ArrayList(){"1","4","Test","^","1","67","43","4","Ret","78"};

             for (int i = 0; i < obj.Count; i++)
             {
                 Console.Write(obj[i] + " ");
             }

             GetDuplicateArryValue(obj);
        }

        public static void GetDuplicateArryValue(ArrayList arr)
        {
            //to store all the duplicate values in Array list
            ArrayList dup = new ArrayList();

            for (int i = 0; i < arr.Count; i++)
            {
                for (int j = i + 1; j < arr.Count; j++)
                {
                    if (arr[i].Equals(arr[j]))
                    {
                        //When duplicate value is found, check
                        //whether the value not contained in the dup array list
                        if (!dup.Contains(arr[i]))
                        {
                            dup.Add(arr[i]);
                        }
                    }
                }
            }
            Console.WriteLine("\n Duplicates Number Are");

            for (int i = 0; i < dup.Count; i++)
            {
                Console.Write(dup[i] + " ");
            }
            Console.WriteLine();
        }
    }


OUTPUT :

Fibonacci Series in C#

Generating the febonacci series in C#

class Program
    {
        static void Main(string[] args)
        {
            string InuputString = "Febonacci Series \n";
             Console.WriteLine(InuputString);
             GenerateFibonacciSeries(10);
        }

        public static  void GenerateFibonacciSeries(int value)
        {
          
            int ftemp = 0;
           
            int f1 = 1;
            //temporary variable
            int f2 = 0;
            Console.Write(f1);
            //loop through all the numbers
            for (int i = 0; i < value; i++)
            {
                //assign temporary variable
                f2 = ftemp;
                ftemp = f1;
                f1 = f2 + ftemp;

                Console.Write(" ");
                Console.Write(f1);
            }

        }
    }


Output :

C# Palindrome Code

Sample code for Palindrome  in C#.


    class Program
    {
        static int strLen = 0;
        static int numLen = 0;
        static void Main(string[] args)
        {
            string InuputString = "Testset";
             Console.WriteLine(InuputString);
             ISPalindrome(InuputString);
        }

        public  static void ISPalindrome(string str)
        {

            strLen = str.Length;
            str = str.ToLower();

            while (numLen < strLen)
            {

                if (str[numLen] != str[strLen - 1])
                {
                    Console.WriteLine("Not a Palindrome");
                    break;
                }

                else
                {
                    numLen++;
                    strLen--;

                    if (numLen > strLen - 1)
                    {
                        Console.WriteLine("Palindrome");
                    }

                }

            }
        }
    }




Difference between x.equal(y) and x==y

The equal and == operator are used to compersion check and both are returning the Boolean value(true or false)

For value type both of them are working same.
e.g.
 int a= 10;
int b= 10;
if(a==b) // true;
if(a.equal(b)) // true


But for reference type both of them are behaving different.

e.g
StringBuilder sb1 = new StringBuilder(“Value”);
StringBuilder sb2 = new StringBuilder(“Value”);
If(sb1 == sb2) // false
If(sb1.equal(sb2)) // true


Thursday, 3 July 2014

Could not load file or assembly 'Oracle.DataAccess, Version=4.121.1.0


Could not load file or assembly 'Oracle.DataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.

It is problem due to application is not pointing to proper DDL of oracle access and your GAC is having different version of Oracle.DataAccess.

To correct this you just need to put the below code into web.config file.

<runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
         <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/>
         <bindingRedirect oldVersion="4.121.1.0" newVersion="4.112.1.2"/>
      </dependentAssembly>
   </assemblyBinding
  </runtime>

By doing this when application is looking to the version which is not exist then it will redirect to the exist DLL version.

Generally by doing this you can work with the two same DDL with dirffrent version and based on the requirement you can call the version of DLL

Monday, 28 April 2014

Exporting the gridview data to excel sheet;


Create a grid view and bind the data to grid view now suppose your grid view is looking like below image;



Code for grid view

Sunday, 13 April 2014

selected row in datagridview c#

Getting the seltected rwo in the data grid from code behind in C#.

Suppose you give the name of data grid as dg;


Just do compy and paste of the below code you will get the row selected;


   public class EmplyeeBAO
    {
        private ArrayList GetSelectedRows(DataGrid dg)
{
   ArrayList al = new ArrayList();
   CurrencyManager cm = (CurrencyManager)this.
                                    BindingContext[dg.DataSource, dg.DataMember];
   DataView dv = (DataView)cm.List;
   for(int i = 0; i < dv.Count; ++i)
   {
     if(dg.IsSelected(i)) // find out the selected rwo
       al.Add(i);
   }
   return al;
}


Saturday, 12 April 2014

SQL Interview Questions and Answer

Clustered and Non-Clustered Index
What is an Index?
Index is a database object, which can be created on one or more columns (16 Max column combination). When creating the index will read the column(s) and forms a relevant data structure to minimize the number of data comparisons. The index will improve the performance of data retrieval.
Primary Key Constraint
A table column with this constraint is called as the key column for the table. This constraint helps the table to make sure that the value is not repeated and also no null entries. A table can have only one Primary key. Multiple columns can participate on the primary key column. Then, the uniqueness is considered among all the participant columns by combining their values.

Sunday, 30 March 2014

SQL: HAVING CLAUSE

SQL HAVING clause with examples.

DESCRIPTION
The SQL HAVING Clause is mostly combination with GROUP BY Clause to restrict the result set that get from  groups of returned rows to only those whose the condition will be TRUE.


SYNTAX

Syntax for SQL HAVING Clause is:

SELECT expression1, expression2, ... expression_n,  aggregate_function (expression) FROM tables WHERE conditions GROUP BY expression1, expression2, ... expression_n HAVING condition;

·         aggregate_function is a function such as SQL SUM function, SQL MIN function, or SQL MAX function.
·         expression1, expression2, ... expression_n are expressions that are not encapsulated within an aggregate function and must be included in the GROUP BY Clause.
·         condition is the condition that is used to restrict the groups of returned rows.

EXAMPLE - USING SUM FUNCTION

SQL HAVING clause example that uses the SQL SUM function.

SELECT department, SUM(salary) AS "Total salary " FROM Employee GROUP BY department HAVING SUM(salary) > 1000;

SQL SUM functions to return the name of the department and the total salary (in the associated department). The SQL HAVING clause will filter the results so that only departments with sales greater than 1000 will be returned.

EXAMPLE - USING COUNT FUNCTION

The HAVING clause with the SQL COUNT function.

SELECT department, COUNT(*) AS "Number of employees" FROM employees WHERE salary > 25000 GROUP BY department HAVING COUNT(*) > 10;

SQL COUNT functions to return the name of the department and the number of employees (in the associated department) that make over 25,000.

EXAMPLE - USING MIN FUNCTION

We could use the HAVING clause with the SQL MIN function.

SQL MIN functions to return the name of each department and the minimum salary in the department.


SELECT department, MIN(salary) AS "Minimum salary" FROM employees GROUP BY department HAVING MIN(salary) > 35000;