h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

LINQ To Object --Example -2

Today, we will see how to use Order class in LINQ.

Create a One Class Called : ClsEmployee
Three Properties in the Class.


1)EmpId2)Name3)Salary
public string Name { get; set; } public string EmpID { get; set; } public int Salary { get; set; }
Create a One form
Drag and Drop one Button.
Button name is btn_Result.
Create a Method:
Method name is "InsertintoTable()
List objEmployee = new List { new ClsEmployees { EmpID = "1001" ,Name ="GANTEC", Salary =10000 }, new ClsEmployees { EmpID = "1002" ,Name ="IBM", Salary =15000 }, new ClsEmployees { EmpID = "1003" ,Name ="CTS", Salary =20000 }, new ClsEmployees { EmpID = "1004" ,Name ="WIPRO", Salary =30000 }, new ClsEmployees { EmpID = "1005" ,Name ="SATHYAM", Salary =40000 }, new ClsEmployees { EmpID = "1006" ,Name ="BUTTERFLY", Salary =50000 }, new ClsEmployees { EmpID = "1007" ,Name ="CON", Salary =10000 }, new ClsEmployees { EmpID = "1008" ,Name ="TVS", Salary =75000 }, new ClsEmployees { EmpID = "1010" ,Name ="TATA", Salary =90000 }, new ClsEmployees { EmpID = "1009 " ,Name ="GANTEC COR", Salary =100000 }, };
Call this method in button Click Event and Add below codes,
var OrderBy = (from emp in objEmployee select emp).OrderBy(x => x.Name);

Happy Coding!!!

LINQ To Object -- Example 1

 Count of Rows in the Table using LINQ
1) Create a One Class Called : ClsEmployee
Three Properties in the Class.
1)EmpId2)Name3)Salary
Code :
   public string Name { get; set; }
   public string EmpID { get; set; }
   public int Salary { get; set; }
2)  Create a One form
Drag and Drop one Button.
Button name is btn_Result.
Create a Method:

Method name is "InsertintoTable()
   List<ClsEmployees> objEmployee = new List<ClsEmployees>
            {
                new ClsEmployees { EmpID = "1001" ,Name ="GANTEC", Salary =10000 },
                new ClsEmployees { EmpID = "1002" ,Name ="IBM", Salary =15000 },
                new ClsEmployees { EmpID = "1003" ,Name ="CTS", Salary =20000 },
                new ClsEmployees { EmpID = "1004" ,Name ="WIPRO", Salary =30000 },
                new ClsEmployees { EmpID = "1005" ,Name ="SATHYAM", Salary =40000 },
                new ClsEmployees { EmpID = "1006" ,Name ="BUTTERFLY", Salary =50000 },
                new ClsEmployees { EmpID = "1007" ,Name ="CON", Salary =10000 },
                new ClsEmployees { EmpID = "1008" ,Name ="TVS", Salary =75000 },
                 new ClsEmployees { EmpID = "1010" ,Name ="TATA", Salary =90000 },
                 new ClsEmployees { EmpID = "1009" ,Name ="GANTEC COR", Salary =100000 },
             };
Call this method in button Click Event and Add below codes,
 var CountofRows = (from emp in objEmployee select emp.Salary).Count();
 MessageBox.Show("Total Records in Employee Table :" + CountofRows );
Result: "Total Records in Employee Table: 10" in the Message Box

Date Format Directory

Today, we discussed Date Format Directory in C#.Net

Code:
public static void CreateDirectory(string DesignationPath) { if (!Directory.Exists(DesignationPath)) { Directory.CreateDirectory(DesignationPath); } } public static string currentYear() { string Year = string.Empty; DateTime dt = DateTime.Now; string format = "yyyy"; Year = dt.ToString(format); return Year; } public static string currentMonth() { string Month = string.Empty; DateTime dt = DateTime.Now; string format = "MM"; Month = dt.ToString(format); return Month; } public static string currentDate() { string day = string.Empty; DateTime dt = DateTime.Now; string format = "dd"; day = dt.ToString(format); return day; }

Set Excel File Format in C#.Net

Set Excel File Format in C#.net

  public static string ExcelFileType()
        {
            string excelFileType = string.Empty;
            Microsoft.Office.Interop.Excel.Application OfficeFileType = new Microsoft.Office.Interop.Excel.Application();
            OfficeFileType.Visible = false;
            string oVersionName = OfficeFileType.Version;
            int length = oVersionName.IndexOf('.');
            oVersionName = oVersionName.Substring(0, length);
            int versionNumber = int.Parse(oVersionName, CultureInfo.GetCultureInfo("en-US"));
            if (versionNumber >= 12)
            {
                excelFileType = ".xlsx";
            }
            else
            {
                excelFileType = ".xls";
            }

            return excelFileType;
        }

MS Office Version in C#.Net

"MS Office Version in C#.Net
public static string GetOfficeVer()
{
string sVersion = string.Empty;
Microsoft.Office.Interop.Excel.Application appVersion = new Microsoft.Office.Interop.Excel.Application();
appVersion.Visible = false;
switch (appVersion.Version.ToString())
{
case "7.0":
sVersion = "95";
break;
case "8.0":
sVersion = "97";
break;
case "9.0":
sVersion = "2000";
break;
case "10.0":
sVersion = "2002";
break;
case "11.0":
sVersion = "2003";
break;
case "12.0":
sVersion = "2007";
break;
case "14.0":
sVersion = "2010";
break;
default:
sVersion = "Too Old!";
break;
}
return sVersion;
}