Friday, May 13, 2016

The localhost page isn’t working in visual studio

Resolved::: solution> project properties> change iis express port number ----

Wednesday, March 9, 2016

Convert Datatable to List

private static List<T> ConvertDataTable<T>(DataTable dt)  
{  
    List<T> data = new List<T>();  
    foreach (DataRow row in dt.Rows)  
    {  
        T item = GetItem<T>(row);  
        data.Add(item);  
    }  
    return data;  
}  
private static T GetItem<T>(DataRow dr)  
{  
    Type temp = typeof(T);  
    T obj = Activator.CreateInstance<T>();  
  
    foreach (DataColumn column in dr.Table.Columns)  
    {  
        foreach (PropertyInfo pro in temp.GetProperties())  
        {  
            if (pro.Name == column.ColumnName)  
                pro.SetValue(obj, dr[column.ColumnName], null);  
            else  
                continue;  
        }  
    }  
    return obj;  

Tuesday, March 8, 2016

Visual Studio Expand/Collapse keyboard shortcuts


Collapse to Definitions: CTRL + M + O

Expand all Outlining: CTRL + M + X

Thursday, March 3, 2016

Not Running in Release Mode in Visual Studio

  • Right click Project
  • Properties
  • Build
  • Advanced
  • Set Debug Info to full or pdb only

Tuesday, March 1, 2016

Difference Between "string" and "String"

what is the difference between both (String and string)? After completing the execution of this program when we mouse over on string is shows class System.String and  when we mouse over on String it also shows Class System.String. Class System.String statement clarifying that string is the alias name of String.

Finally:
String is the alias name of String because both contain the same things 

Difference Between "string" and "String"

what is the difference between both (String and string)? After completing the execution of this program when we mouse over on string is shows class System.String and  when we mouse over on String it also shows Class System.String. Class System.String statement clarifying that string is the alias name of String.

Finally:
String is the alias name of String because both contain the same things 

Wednesday, February 24, 2016

Convert Number To Word

public string ConvertNumbertoWords(int number)
       {
           if (number == 0)
               return "ZERO";
           if (number < 0)
               return "minus " + ConvertNumbertoWords(Math.Abs(number));
           string words = "";
           if ((number/1000000) > 0)
           {
               words += ConvertNumbertoWords(number/1000000) + " MILLION ";
               number %= 1000000;
           }
           if ((number/1000) > 0)
           {
               words += ConvertNumbertoWords(number/1000) + " THOUSAND ";
               number %= 1000;
           }
           if ((number/100) > 0)
           {
               words += ConvertNumbertoWords(number/100) + " HUNDRED ";
               number %= 100;
           }
           if (number > 0)
           {
               if (words != "")
                   words += "AND ";
               var unitsMap = new[]
               {
                   "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN",
                   "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN"
               };
               var tensMap = new[]
               {"ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};

               if (number < 20)
                   words += unitsMap[number];
               else
               {
                   words += tensMap[number/10];
                   if ((number%10) > 0)
                       words += " " + unitsMap[number%10];
               }
           }
           return words;

       }

Monday, February 22, 2016

Difference between TextBox and TextBoxFor:

@Html.TextBox() is loosely typed method whereas @Html.TextBoxFor() is a strongly typed (generic) extension method.
TextBox() requires property name as string parameter where as TextBoxFor() requires lambda expression as a parameter.
TextBox doesn't give you compile time error if you have specified wrong property name. It will throw run time exception.
TextBoxFor is generic method so it will give you compile time error if you have specified wrong property name or property name changes. (Provided view is not compile at run time. )

Friday, February 19, 2016

Convert List to Dataset

       public DataSet ToDataSet<T>(IList<T> list)
       {
           Type elementType = typeof(T);
           using (DataSet ds = new DataSet())
           {
               using (DataTable t = new DataTable())
               {
                   ds.Tables.Add(t);
                   //add a column to table for each public property on T
                   PropertyInfo[] _props = elementType.GetProperties();
                   foreach (PropertyInfo propInfo in _props)
                   {
                       Type _pi = propInfo.PropertyType;
                       Type ColType = Nullable.GetUnderlyingType(_pi) ?? _pi;
                       t.Columns.Add(propInfo.Name, ColType);
                   }
                   //go through each property on T and add each value to the table
                   foreach (T item in list)
                   {
                       DataRow row = t.NewRow();
                       foreach (PropertyInfo propInfo in _props)
                       {
                           row[propInfo.Name] = propInfo.GetValue(item, null) ??                                       DBNull.Value;
                       }
                       t.Rows.Add(row);
                   }
               }
               return ds;

           }

Sunday, February 14, 2016

SQL Server Languages – DML, DDL, DCL & TCL

There are mainly 4 types of language statements or commands in SQL Server.
DML
DML is abbreviation of Data Manipulation Language. It is used to retrieve, modify, add, and delete data in database.
Examples: SELECT, UPDATE, INSERT, DELETE statements
1.    SELECT – used for retrieving data from the database.
2.    UPDATE – used for modifying the data in the database.
3.    INSERT – used for adding or inserting new data into database.
4.    DELETE – used for deleting the already existing data from database.
DDL
DDL is abbreviation of Data Definition Language. It is used to create, modify and destroy the structure of database objects in database.
Examples: CREATE, ALTER, DROP, TRUNCATE  statements
1.    CREATE – used for create database objects like tables, stored procedures, functions etc.
2.    ALTER – used for modifying the existing database objects like tables, stored procedures, functions etc.
3.    DROP – used to drop or deleted the existing database objects.
4.    TRUNCATE – used to delete all the records from table and to reset identity of column to initial value.
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
1.    GRANT – used for creating access permissions for users to database.
2.    REVOKE – used for revoking the already assigned permissions.
TCL
TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.
Examples: COMMIT, ROLLBACK, SAVE TRANSACTION statements
1.    COMMIT – used for saving the work done in a particular transaction. For example: “Ctrl + S” in word file.
2.    ROLLBACK – used for reverting the transaction to the original state before commit. For example: “Ctrl + Z” in word file.

3.    SAVE TRANSACTION – used for setting save point in transactions.