Wednesday, December 30, 2015

JSON


JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language.

JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON is built on two structures:
A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

Comparison between XML and JSON

JSON is smaller than XML, and faster and easier to parse.
XML is human-readable data interchange specified in a document format, while JSON is human-readable data interchange data format.
JSON is not extensible because it does not need to be. JSON is not a document markup language, so it is not necessary to define new tags or attributes to represent data in it.
JSON has the same interoperability potential as XML.
JSON is much simpler than XML. JSON has a much smaller grammar and maps more directly onto the data structures used in modern programming languages. 

Thursday, December 17, 2015

useful

TTFB -- Time To First Byte 

Merge Datatable or DataSet

        con.Open();
        SqlDataAdapter adp = new SqlDataAdapter("select * from Reg", con);
        DataSet ds1 = new DataSet();
        adp.Fill(ds1);     
        adp = new SqlDataAdapter("select * from sale", con);
        DataSet ds2 = new DataSet();
        adp.Fill(ds2);      
        ds1.Merge(ds2,true);    
        if (ds1.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count>0)
        {
            GridView1.DataSource = ds1;
            GridView1.DataBind();
        }
        con.Close();

aliasing directives

using Sess=System.Web.HttpContext;

Wednesday, December 16, 2015

Building Solutions in Visual Studio – Build Vs. Rebuild

“Build Solution” and “Rebuild Solution” are the most commonly used features in Visual Studio.  As a developer you writes code, build the solution and run the application in Visual Studio.  Very often you also used “rebuild solution” , or “clean and then build solution”.  Have you ever wonder why there are different options ? When to use them?  Though many of you are familiar with the details of  these but when asked, I have seen many beginners having confusion around it.

So let’s try to simply it by asking below questions
What is the difference between Build and Rebuild ?
When to use which option ?
How does clean relates , when to use it ?
One-liner Understanding…
Build Solution – Incremental build and compiles only the files that are changed.
Clean Solution – Deletes all compiled, intermediate files.
Rebuild Solution – Deletes all compiled files and compiles all irrespective of changes.

Build + Clean = Rebuild

Wednesday, November 18, 2015

Diff b/w For Loop and ForEach Loop




       For Loop
        ForEach Loop   
1
For Loop Variable Always intOnly.
ForEach Loop Variable Same as Type of Values Under Array
2
For loop Iterates a Statement or a Block of Statements Repeatedly until a Specified Expression Evaluates to False.
For-each loop is used to Iiterate through the Items in Object Collections, List Generic Collections or Array List Collections.
3
For Loops are Faster Than For Each Loop.
For Each Loop are Slower Than For Loop.
4
Need To Loop Bounds(Minimum,Maximum).

Ex:
int count=0;
int j;
for(int i=0;i<=5;i++)
{
   j=count+1;
}
No Need To Loop Bounds Minimum or Maximum.

EX:
int z=0;
int [] a=new int[]      {0,1,2,3,4,5}; 
   foreach(int i in a)
    {
    z=z+1;
    }


Friday, November 13, 2015

Csharppad

Compile, run and execute C# Sharp code online in an interactive REPL sandbox with code completion using your browser, iPad, iPhone, tablets and mobile


Csharppad.com

Thursday, November 12, 2015

Debug mode and Release mode

Debug mode and Release mode are different configurations for building your .Net project. Programmers generally use the Debug mode for debugging step by step their .Net project and select the Release mode for the final build of Assembly file (.dll or .exe).

The Debug mode does not optimize the binary it produces because the relationship between source code and generated instructions is more complex. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. The Debug configuration of your program is compiled with full symbolic debug information which help the debugger figure out where it is in the source code.

Is Release mode is faster than Debug mode ?

The Release mode enables optimizations and generates without any debug data, so it is fully optimized. . Lots of your code could be completely removed or rewritten in Release mode. The resulting executable will most likely not match up with your written code. Because of this release mode will run faster than debug mode due to the optimizations.

What is .pdb files ?

Debug information can be generated in a .pdb (Program Database File) file depending on the compiler options that are used. A .pdb file holds debugging and project state information that allows incremental linking of a Debug configuration of your program. A Program Database File is created when you compile a VB.Net or C# program with debug mode.

In Asp.Net ?

It is important to note that Debug mode or Release mode in a web application is controlled by the web.config file, not your settings within Visual Studio.

    <compilation debug="true">

What Is MVC?

MVC is a software architecture and  design patterns - the structure of the system - that separates domain/application/business (whatever you prefer) logic from the rest of the user interface. It does this by separating the application into three parts: the model, the view, and the controller.
The model manages fundamental behaviors and data of the application. It can respond to requests for information, respond to instructions to change the state of its information, and even to notify observers in event-driven systems when information changes. This could be a database, or any number of data structures or storage systems. In short, it is the data and data-management of the application.
The view effectively provides the user interface element of the application. It'll render data from the model into a form that is suitable for the user interface.
The controller receives user input and makes calls to model objects and the view to perform appropriate actions.

Trigger

Trigger:
èAfter Triggers (For Triggers)
èInstead Of Triggers
 After Triggers
These triggers run after an insert, update or delete on a table. They are not supported for views. 
AFTER TRIGGERS can be classified further into three types as:
     AFTER INSERT Trigger.
     AFTER UPDATE Trigger.
    AFTER DELETE Trigger.
CREATE TABLE Employee_Test
(
Emp_ID INT Identity,
Emp_name Varchar(100),
Emp_Sal Decimal (10,2)
)

INSERT INTO Employee_Test VALUES ('Anees',1000);
INSERT INTO Employee_Test VALUES ('Rick',1200);
INSERT INTO Employee_Test VALUES ('John',1100);
INSERT INTO Employee_Test VALUES ('Stephen',1300);
INSERT INTO Employee_Test VALUES ('Maria',1400);


AFTER INSERT TRIGGER
CREATE TABLE Employee_Test_Audit
(
Emp_ID int,
Emp_name varchar(100),
Emp_Sal decimal (10,2),
Audit_Action varchar(100),
Audit_Timestamp datetime
)

 After Insert Trigger

This trigger is fired after an INSERT on the table.
CREATE TRIGGER trgAfterInsert ON [dbo].[Employee_Test]
FOR INSERT
AS
          declare @empid int;
          declare @empname varchar(100);
          declare @empsal decimal(10,2);
          declare @audit_action varchar(100);

          select @empid=i.Emp_ID from inserted i; 
          select @empname=i.Emp_Name from inserted i;
          select @empsal=i.Emp_Sal from inserted i;        
          set @audit_action='Inserted Record -- After Insert Trigger.';

          insert into Employee_Test_Audit
           (Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
          values(@empid,@empname,@empsal,@audit_action,getdate());

          PRINT 'AFTER INSERT trigger fired.'
GO
To see the newly created trigger in action, lets insert a row into the main table as:
insert into Employee_Test values('Chris',1500);

Now, a record has been inserted into the Employee_Test table. The AFTER INSERT trigger attached to this table has inserted the record into the Employee_Test_Audit as:

AFTER UPDATE Trigger

This trigger is fired after an update on the table. Let’s create the trigger as:
CREATE TRIGGER trgAfterUpdate ON [dbo].[Employee_Test]
FOR UPDATE
AS
          declare @empid int;
          declare @empname varchar(100);
          declare @empsal decimal(10,2);
          declare @audit_action varchar(100);

          select @empid=i.Emp_ID from inserted i; 
          select @empname=i.Emp_Name from inserted i;
          select @empsal=i.Emp_Sal from inserted i;        
         
          if update(Emp_Name)
                   set @audit_action='Updated Record -- After Update Trigger.';
          if update(Emp_Sal)
                   set @audit_action='Updated Record -- After Update Trigger.';

          insert into Employee_Test_Audit(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
          values(@empid,@empname,@empsal,@audit_action,getdate());

          PRINT 'AFTER UPDATE Trigger fired.'
GO

AFTER UPDATE
update Employee_Test set Emp_Sal=1550 where Emp_ID=6
This inserts the row into the audit table as:

After Update Trigger.   
(c) AFTER DELETE Trigger
This trigger is fired after a delete on the table

CREATE TRIGGER trgAfterDelete ON [dbo].[Employee_Test]
AFTER DELETE
AS
          declare @empid int;
          declare @empname varchar(100);
          declare @empsal decimal(10,2);
          declare @audit_action varchar(100);

          select @empid=d.Emp_ID from deleted d;
          select @empname=d.Emp_Name from deleted d;         
          select @empsal=d.Emp_Sal from deleted d;       
          set @audit_action='Deleted -- After Delete Trigger.';

          insert into Employee_Test_Audit
(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
          values(@empid,@empname,@empsal,@audit_action,getdate());

          PRINT 'AFTER DELETE TRIGGER fired.'
GO

-- After Delete Trigger.  All the triggers can be enabled/disabled on the table using the statement

ALTER TABLE Employee_Test {ENABLE|DISBALE} TRIGGER ALL
Specific Triggers can be enabled or disabled as:

ALTER TABLE Employee_Test DISABLE TRIGGER trgAfterDelete
This disables the After Delete Trigger named trgAfterDelete on the specified table.
è Instead Of Triggers
INSTEAD OF TRIGGERS can be classified further into three types as:
=>      INSTEAD OF INSERT Trigger.
=>       INSTEAD OF UPDATE Trigger.
=>       INSTEAD OF DELETE Trigger.
Lets create an Instead Of Delete Trigger as:

CREATE TRIGGER trgInsteadOfDelete ON [dbo].[Employee_Test]
INSTEAD OF DELETE
AS
          declare @emp_id int;
          declare @emp_name varchar(100);
          declare @emp_sal int;
         
          select @emp_id=d.Emp_ID from deleted d;
          select @emp_name=d.Emp_Name from deleted d;
          select @emp_sal=d.Emp_Sal from deleted d;

          BEGIN
                   if(@emp_sal>1200)
                   begin
                             RAISERROR('Cannot delete where salary > 1200',16,1);
                             ROLLBACK;
                   end
                   else
                   begin
                             delete from Employee_Test where Emp_ID=@emp_id;
                             COMMIT;
                             insert into Employee_Test_Audit(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
                             values(@emp_id,@emp_name,@emp_sal,'Deleted -- Instead Of Delete Trigger.',getdate());
                             PRINT 'Record Deleted -- Instead Of Delete Trigger.'
                   end
          END
GO