Generate Log File in C#

This article demonstrates how to create a simple text based log file to log error messages with your own format using a C# class. Create a Class Name as LogFileGeneration using System.IO; using System.Text; private string sLogFormat; private string sErrorTime; public LogFileGeneration () { //sLogFormat used to create log files format : // dd/mm/yyyy hh:mm:ss AM/PM ==> Log Message sLogFormat = DateTime.Now.ToShortDateString().ToString()+” “+DateTime.Now.ToLongTimeString().ToString()+” ==> “; //this variable used to create log filename format ” //for example filename : ErrorLogYYYYMMDD string sYear = DateTime.Now.Year.ToString(); string sMonth = DateTime.Now.Month.ToString(); string sDay = DateTime.Now.Day.ToString(); sErrorTime = sYear+sMonth+sDay; } public void ErrorLog(string sPathName, string … Continue reading Generate Log File in C#

Difference Between Temporary Table and Table Variable

Both Temporary Tables (# Tables) and Table Variables ( @ Tables) in Sql Server provide a mechanism for Temporary holding/storage of the result-set for further processing. Below table lists out some of the major difference between Temporary Table and Table Variable. Each of these differences are explained in-detail with extensive list of examples in the next articles in this series which are listed above. 1. SYNTAX Below is the sample example of Creating a Temporary Table, Inserting records into it, retrieving the rows from it and then finally dropping the created Temporary Table. — Create Temporary Table CREATE TABLE #Customer (Id INT, Name VARCHAR(50)) … Continue reading Difference Between Temporary Table and Table Variable

How Can i Use Pivot In sql Server with Example

CREATE TABLE #BookSales (BookType VARCHAR(20), SalesYear INT, BookSales MONEY); GO INSERT INTO #BookSales VALUES(‘Fiction’, 2014, 11201); INSERT INTO #BookSales VALUES(‘Fiction’, 2014, 12939); INSERT INTO #BookSales VALUES(‘Fiction’, 2013, 10436); INSERT INTO #BookSales VALUES(‘Fiction’, 2013, 9346); INSERT INTO #BookSales VALUES(‘Nonfiction’, 2014, 7214); INSERT INTO #BookSales VALUES(‘Nonfiction’, 2014, 5800); INSERT INTO #BookSales VALUES(‘Nonfiction’, 2013, 8922); INSERT INTO #BookSales VALUES(‘Nonfiction’, 2013, 7462); SELECT * FROM #BookSales PIVOT(SUM(BookSales) FOR SalesYear IN([2013], [2014]) ) AS PivotSales;       Pivot Continue reading How Can i Use Pivot In sql Server with Example

Write a c program to subtract two numbers without using subtraction operator

Write a c program or code to subtract two numbers without using subtraction operator   #include<stdio.h> int main(){   int a,b; int sum; printf(“Enter any two integers: “); scanf(“%d%d”,&a,&b); sum = a + ~b + 1; printf(“Difference of two integers: %d”,sum); return 0; } Sample Output: Enter any two integers: 5 4 Difference of two integers: 1 Continue reading Write a c program to subtract two numbers without using subtraction operator

Write a c program to add two numbers without using addition operator

Add two numbers in c without using operator How to add two numbers without using the plus operator in c #include<stdio.h> int main(){   int a,b; int sum; printf(“Enter any two integers: “); scanf(“%d%d”,&a,&b); //sum = a – (-b); sum = a – ~b -1; printf(“Sum of two integers: %d”,sum); return 0; }   Sample output: Enter any two integers: 5 10 Sum of two integers: 15 Algorithm: In c ~ is 1’s complement operator. This is equivalent to: ~a = -b + 1 So, a – ~b -1 = a-(-b + 1) + 1 = a + b – 1 + 1 = a … Continue reading Write a c program to add two numbers without using addition operator

Reverse any number using c program

Code 1: Write a c program to reverse a given number C program to find reverse of a number C program to reverse the digits of a number Reverse of a number in c using while loop #include<stdio.h> int main(){ int num,r,reverse=0; printf(“Enter any number: “); scanf(“%d”,&num); while(num){ r=num%10; reverse=reverse*10+r; num=num/10; } printf(“Reversed of number: %d”,reverse); return 0; } Sample output: Enter any number: 12 Reversed of number: 21 Code 2: Reverse very large or big numbers beyond the range of long int Reverse five digit number c program Logic is we accept the number as string #include<stdio.h> #define MAX 1000 int main(){ char num[MAX]; int i=0,j,flag=0; … Continue reading Reverse any number using c program