Skip to main content

Posts

Showing posts from November, 2014

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Example of SQL Injection attack

SQL Injection means, Inject the database by the SQL Query, this query executed by the input control like TextBox, URL etc. Suppose we have a table department and we want to retrieve some data from the table by the TextBox. You want to retrieve all the rows, which is related to first department no. Now, you should to enter 1 in the TextBox, then you will get rows, which is related to putted number in the TextBox. If you want to put some number like: 1 or 1=1 then you will get all rows which is available in the table. If this query is executed it means deletion is also possible with the table.Like 1;Drop table table_name Source Code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="my.aspx.cs" Inherits="my" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title>  </head> <body> <form id="form1" runat="server">

Data Modification Language (DML) Triggers in SQL

A DML trigger is fired when data in the underlying table is affected by DML statements, such as INSERT, UPDATE, or DELETE. These triggers help in maintaining consistent, reliable, and correct data in tables. They enable the performance of complex action and cascade these actions to other dependent tables. Cascading is the process of reflecting the changes made in a table in the other related tables. The DML triggers have the following characteristics: Fired automatically by the SQL Server whenever any data modification statement is issued. Cannot be explicitly invoked or executed, as in the case of the stored procedures. Prevents incorrect, unauthorized, and inconsistent changes in data. Cannot return data to the user. Can be nested up to 32 levels. The nesting of triggers occurs when a trigger performs an action that initiates another trigger. Whenever a trigger is fired in response to the INSERT, DELETE, or UPDATE statement, the SQL Server creates two temporary tables, calle

How to add controls dynamically in windows form c#

Visual studio provide the best features to design the form. By the designer window, you can add the controls from the toolBox. After added the items, you can set the properties by the property window. Same this things, you can do this by the code window. Follow some steps to add controls dynamically.   Step-1 : Open Code window that is form1.cs file, create a object for controls like TextBox t1 = new TextBox(); Step-2 : Associate properties of the TextBox class with the current object like  t1.Name = "Text1";     t1.Width = 300;             t1.Text = " Dynamically added Control";             t1.Location = new Point(10, 10); Here Point is a class, in which you have to define the coordinates of x-axis and y-axis, where you want to add the TextBox. Step-3 : Add this instance in the form by following line of code.  this.Controls.Add(t1);  Now code Generate the following output:

Design a program to find largest of four numbers

The logic behind the program is, Take four variable like a, b, c, d for numbers also take another variable like large for comparing among three numbers. First of all, assign the value of variable a into the large variable. Compare among three numbers with the large variable. If any one is find larger then you have to assign this variable value into the larger variable. Example #include <stdio.h> #include<conio.h> main() { int a,b,c,d; int large; clrscr(); printf("Enter four numbers:\n"); scanf("%d%d%d%d",&a,&b,&c,&d); large=a; if(b>large) large=b; if(c>large) large=c; if(d>large) large=d; printf("The largest number is %d",large); } Output Of the Given program is

How to draw rectangle in applet

Four coordinate are required For drawing the rectangle in the java applet. First two coordinate define the origin point of the rectangle. Origin point start from upper left corner and further x-coordinate increases width of the rectangle in right side and y-coordinate increases height of the rectangle in downward. Syntax of drawRect in Java Applet Graphics_Instance . drawRect(int X1, Int Y1, int Width, int Height); If you want to set border color of the rectangle then use setColor( ) method of Graphics class, which is exist in java.awt package. Example - designline.java import java.awt.*; import java.applet.*; public class designline extends Applet { int width, height;    public void init() {           setBackground( Color.gray);    }    public void paint( Graphics g ) {           g.setColor( Color.red );       g.drawRect( 11, 22, 101, 50 ); } } First to compile the code and create the class file for this Prepare the HTML file in the same location wit

How to draw Line in Applet

Four coordinate are required For drawing the line in the java applet. First two coordinate define the origin point of the line. Origin point start from upper left corner and further x-coordinate increase in right side and y-coordinate increase downward. Syntax of drawLine in Java Applet Graphics_Instance . drawLine(int X1, Int Y1, int X2, int Y2); If you want to set color on line then use setColor( ) method of Graphics class, which is exist in java.awt package. Example - designline.java import java.awt.*; import java.applet.*; public class designline extends Applet { int width,height; public void init() { setBackground(Color.black); } public void paint(Graphics g) { g.setColor(Color.green); g.drawLine(0,0,200,200); } } Compilation of Applet code and generate the class file Prepare the HTML file in the same location with <applet> tag. Like <applet code="designline" width="400" height="400" /> Save the .html

Compiling and Running Java Programs

There are various steps to compiling and running java programs, these are Step-1 : First to install JDK, JRE and JVM into the System. Step-2 : Prepare source code in any editor like notepad, c++ editor etc. Step-3: class HelloWorld { public static void main(String r[]) { int a=10, b=10,c; c=a+b; System.out.println("Output of the program is"+c); } } Step-4 : Save the source code in the java bin directory. Class name which contain main method should same of the file name. Example :  HelloWorld (class name)                   HelloWorld.java (file name) Step-5 : Open command prompt and change the directory where your java program has been saved. Suppose your java software installed in C:/>. Now, compiling steps is: C:/java/jdk1.7.0/bin> Javac filename.java   (press Enter) C:/java/jdk1.7.0/bin> Java  filename.java    (press Enter) Step-6:  During compilation, if program generate errors, it means you can't run your program.                 

Execute Batches multiple times using Stored Procedures in SQL

Batches are temporary in nature. To execute a batch more than once, you need to recreate SQL statements and submit them to the server. This leads to an increase in the overhead, as the server needs to compile and create the execution plan for these statements again. Therefore, if you need to execute a batch multiple times, you can save it within a stored procedure. A stored procedure is a precompiled object stored in the database. Stored procedures can invoke the Data Definition Language (DDL) and Data Manipulation Language (DML) statements and can return values. If you need to assign values to the variables declared in the procedures at the run time, you can pass parameters while executing them. You can also execute a procedure from another procedure. This helps in using the functionality of the called procedure within the calling procedure. Creating Stored Procedures You can create a stored procedure by using the CREATE PROCEDURE statement. The syntax of the CREATE PROCEDURE s

Implementing Triggers and its Types in SQL

In a relational database, data in a table is related to other tables. Therefore, while manipulating data in one table, you need to verify and validate its effect on data in the related tables. In addition, you might need to manipulate data in a table after inserting or updating data in another table. You also need to ensure that if an error occurs while updating the data in a table, the changes are reverted. This helps in maintaining data integrity. The SQL Server allows you to implement triggers and transactions to maintain data integrity. This article explains different types of triggers that can be created in SQL Server. Next, we will discusses how to implement triggers to enforce data integrity. Further, we will discuss about how to implement transactions. Implement Triggers At times, while performing data manipulation on a database object, you might also need to perform another manipulation on another object. For example, in an organization, the employees use the Online Le

Commonly used jQuery Event Methods: jQuery

All the DOM events have its equivalent jQuery methods that may be implement by programmer as per the requirement. Anything happens through input devices on the web-page is called an event. All these events have its unique names e.g. clicking on the page, pressing key, hovering mouse etc. According to jQuery masters, these events have some categories, some of them listed below: Keyboard events: KeyDown, KeyUp and KeyPress etc. Mouse events: Click, double click, mouse hover, mouse enter and mouse leave etc. Form events: submit, focus, blur etc.  Document/window events: Load, UnLoad, scrolling, resizing etc. All these events have its own method, discussed earlier in changing default behavior . Some of those events have listed below with example: $(document).ready() Whenever the document/page is ready, this event have triggered. Anything written in this event have been executed just after the page loaded. All the events except functions must be written in this event to be ex

Merits of bottom-up technique

The details of the sub-problem solutions are available in advance in the form of bottom level modules. The individual sub-problem solutions are designed with great details. The main solution can be planned later depending on the available sub-task solutions. The main solution is used to link all the sub-problem solutions. The sub-solutions obtained are simple A complex main module is designed later using these simpler solutions. This technique is more general and code are reusable. This technique simplifies maintenance and the new features can be added easily. This decision of the final solution can be delayed to make it more effective for implementation. Testing in this case is simple and test cases can be designed very easily.

Demerits of top-down technique

This technique is mainly useful for small-scale problems. It is only useful in solving a part of a larger problem. This technique is a poor approach for solving larger problems  This technique is also poor for designing larger programs. The application developed using this technique cannot be upgraded easily. Related Links Merits of top-down technique Features of top-down technique

Merits of top-down technique

The summary of the program plan is known in advance in the form of top module. Parallel development of the program is possible because of independent design of the modules at different levels. Parallel development helps in designing the program at reduced time period. Testing and debugging are faster because of independent testing of modules. Attention can be given to individual level task to improve the efficiency. The hierarchy of the levels helps in understandable low level modules. Handling and management of the modules are easy. This technique improves the code reliability.

Features of top-down technique

Program preparation is stretched to a number of levels  In place of writing long list of statements, the statements are separated into different modules at various levels. The stretching is most general to most specific. Program is structured as hierarchy of various tasks. As the techniques moves from top to bottom, it is a type of specialization. Main module can be designed well before without requiring details of complete design. Testing can be done after inserting down level modules one-by-one. Parallel development is possible because of top and down level modules design.

Rules for making Flowchart

"What are the rules for making the flowchart?" Rule 1 : The flowchart should contain one start and one stop box (terminator). Rule 2 : The symbols of the flowchart are always labeled with simple codes. Rule 3 : The codes used in the flowchart should not give more than one meaning. Rule 4 : The control flows are always represented by directed arrows. Rule 5 : The control flow lines touch the boundary of any box either while leaving from or while entering into the box. Rule 6 : The control flow lines should not cross each other. Rule 7 : The flow line moves in vertical direction either from top to bottom or from bottom to top. Rule 8 : The flow line moves in horizontal direction either from left to right or from right to left. Rule 9 : Only one flow line comes out from all the boxes or symbols excepts decision box. Rule 10 : Two lines can flow from the decision box if single condition is checked. It means a single condition results in one of the two values TRUE or F

Design an algorithm to search a number using binary search technique

Binary Search algorithm is applied where we want to search number in sorted numbers. In this algorithm, first to find mid position of the list and divide the list into two parts. If number is equal to mid then position find easily , this is the  best case of binary search. Problem: Design an algorithm to search a number using binary search technique. Input : A list (array) of numbers in ascending order, number of elements in the list and key to search. Output: Returns 1 if the key is found otherwise returns 0 BIN_SEARCH(LIST, N, KEY) [LIST is an array of numbers in ascending order] [N is the size of the array and KEY is the number to search] L <-- 0;  H<-- N-1;  [Assuming that array index start from 0] M <-- INT ( (L+H) /2 ) [Get the quotient or integer part after division] Repeat While (L <= H) If(Key == LIST[M]) then: Return 1                [Key found] Else: If(Key < LIST[M] ) then: H <-- M-1                     [Move to the left half of the lis

Design an algorithm to search a number using linear search technique

Problem: Design an algorithm to search a number using linear search technique. Input :  A list (array) of numbers, number of elements in the list and key to search. Output : Returns 1 if the key is found otherwise returns 0. LSEARCH(LIST, N, KEY) [LIST is an array of numbers, N is the size of the array and key is the number to search] Repeat For I=0, 1, 2, 3......N-1 [Assuming that array index starts from 0] If(Key == LIST[I]) then: Returns 1 [End of If] Returns 0 Exit.

Design an algorithm to find sum of 'N' natural numbers

Problem: Design an algorithm to find sum of 'N' natural numbers between N1 and N2. Input : Two numbers N1 and N2. Output: Sum of N natural numbers. SUM(N1, N2) [N1 and N2 are two different natural numbers] If N1> N2 then: MAX <-- N1 MIN <-- N2 ELSE: MAX<-- N2 MIN <-- N1 [End of If] MIN <-- MIN-1 [ to include MIN in sum] SUM 1 <-- (MIN * (MIN+1))/2 SUM 2 <-- (MAX * (MAX+1))/2 Return SUM2- SUM1 Exit. In the above algorithm to find the sum of N natural numbers, the formula N(N+1)/2 is used. Instead of a formula, repetitive statements can also be used that run from MIN to MAX with step 1. The algorithm can be re-written as: II algorithm  Problem:  Design an algorithm to find sum of 'N' natural numbers between N1 and N2. Input :  Two numbers N1 and N2. Output:  Sum of N natural numbers. SUM(N1, N2) [N1 and N2 are two different natural numbers] If N1> N2 then: MAX <-- N1 MIN <-- N2 ELSE: MAX<-- N2 MIN

Design an algorithm to find the GCD and LCM of two positive numbers

Problem : Design an algorithm to find the GCD (Greatest Common Divisor) of two positive numbers and use the same to find LCM of two positive numbers. Input: Two Numbers Output : Least Common Multiple of two numbers. GCD(NUM1, NUM2) Rem <-- NUM1 % NUM2  [% Modulus Operator] Repeat While Rem <> 0 NUM1 <-- NUM2 NUM2 <-- Rem Rem <-- NUM1 % NUM2 [End of While] Return NUM2 Exit. LCM(NUM1, NUM2) Return (NUM1 * NUM2) / GCD( NUM1, NUM2) Exit. NOTE : Here in this example algorithm, finding LCM in the main problem that can be divided into sub-problem like finding the GCD first and using the same to solve the main problem. So, GCD algorithm is written first and than the other algorithm that can be divided into small problems and algorithm can be written to solve such small problems. Tracing Suppose that the LCM algorithm is called using 12 and 16. The algorithm calls GCD with 12 and 16. Rem <-- 12 % 16 i.e. Rem= 12 Rem is not equal to zero. So, N

Design an algorithm to find minimum of two distinct numbers

Problem:  Design an algorithm to find minimum of two distinct numbers and using the same, find minimum of three distinct numbers. Input :  For sub-algorithm 2 numbers and for main algorithm 3 numbers. Output: Minimum number MIN_OF_2(NUM1, NUM2)                                                   [Sub-Algorithm] [NUM1 and NUM2 are two numbers] If NUM1<NUM2 Then: Return NUM1 Else: Return NUM2 [End of If] Exit MIN_OF_3(NUM1,NUM2,NUM3)                                     [Main Algorithm] [NUM1, NUM2, and NUM3 are distinct numbers] Returns MIN_OF_2(MIN_OF_2(NUM1, NUM2), NUM3) Exit

Algorithm to find maximum of two unequal numbers

Problem: Algorithm to find maximum of two unequal numbers and use the same to find maximum of four unequal numbers. Input: For sub-algorithm 2 numbers and for main algorithm 4 numbers. Output : Returns the maximum of 4 numbers MAX_OF_2(NUM1, NUM2)      [Sub-algorithm] [NUM1 and NUM2 are two numbers] If(NUM1>NUM2) Then: Returns NUM1 Else: Return NUM2 [End of If] Exit. MAX_OF_4(NUM1, NUM2, NUM3, NUM4) [NUM1, NUM2, NUM3, and NUM4 are numbers] TEMP1 <-- MAX_OF_2(NUM1, NUM2) TEMP2 <-- MAX_OF_2(NUM3, NUM4) MAX   <-- MAX_OF_2(TEMP1, TEMP2) Return MAX Exit.

Design an algorithm to find average of salary

This example is little complex. You will understand it more clearly after reading the user defined data types. Problem: Design an algorithm to find average of SALARY in an array of EMP struct containing information EMPNO, EMPNAME, and SALARY. Input: A list employees of the type struct. Output : Display the average of SALARY. AVG_SALARY(LIST, SIZE) [LIST is an array of EMP, SIZE is size of array] SUM<-- 0 Repeat For I=1,2,3,........SIZE SUM<--SUM +LIST[I].SALARY [END of For I] AVG <-- SUM / SIZE Write :  'The average Salary is', AVG Exit Note : An algorithm, that perform sub-task, may be called in another algorithm. It is a better practice to divide the given problem into sub-problems ans write the individual algorithm to solve such sub-problems. Write the main algorithm to call the sub-algorithms in order to solve the main problem.

Design an algorithm to find the average

Problem :  Design an algorithm to find the average of a subject marks of 'N' number of students. Input: A list of marks and number of students. Output: Returns the average marks calculated. AVG_OF_MARKS(LIST,N) [LIST is an array containing marks, N is the size of array] SUM <-- 0 Repeat For I=1,2,3,.........N SUM<-- SUM+LIST[I] [END of For I] AVG <-- SUM/N Returns AVG Exit

Design an algorithm to find the grade on the basis of the following criteria

Marks Obtained                                                                                       Grade 85 or above 85                                                                                             S 75 or above 75                but less than 85                                                    A 65 or above 65                but less than 75                                                    B 55 or above 55                but less than 65                                                    C 50 or above 50                but less than 55                                                    D Less than 50                                                                                                 F Input :      Marks obtained Output  : Returns the grade on the basis of given criteria GRADE(M) [M is the marks obtained] if(M>= 85) Then: Returns 'S' Else: If (M>= 75) Then: Returns 'A' Else: If(M>=65) Then: Returns 'B&#

Creating Table-Valued Functions in SQL

A table-valued function returns a table as an output, which can be derived as a part of a SELECT statement. Table-valued function return the output as a table data type. The table data is a special data type used to store a set of rows, which return the result set of a table-valued function. Table-valued functions are of two types: Inline Table-Valued Function An inline table-valued function returns a variable of a table data type from the result set of a single SELECT statement. An inline function does not contain a function body within the BEGIN and END statements. Consider an example where the inline table-valued function, fx_Department_GName, accepts a group name as parameter and returns the details of the departments that belong to the group from the Department table. You can create the function by using the following statement: CREATE FUNCTION fx_Department_GName ( @GrName nvarchar (20) ) RETURNS table AS RETURN ( SELECT * FROM HumanResources.Department WHERE GroupN

Creating Scalar functions in SQL

In earlier article we have discussed about user defined functions that have the limited scope in sql programming in compare to stored procedures. User defined function have two types i.e. scalar function and table-valued function. In this article we will discuss about scalar functions. Scalar function accept a single parameter and return a single data value of the type specified in the RETURNS clause. A scalar function can return any data type except text, ntext, image, cursor, and timestamp. Some scalar functions, such and current_timestamp, do not require any arguments. A function contains a series of T-SQL statements defined in a BEGIN…END block of the function body that returns a single value. Consider an example of a scalar function that calculates the monthly salary of the employees accepting the pay rate as an input and returning a single value after multiplying the value with the number of hours and number of days: CREATE FUNCTION HumanResources.MonthlySal (@PayRate fl