Tuesday 22 July 2014

What is a cascading update?

Referential integrity constraints require that foreign key value in one table correspond to primary key values in another. If the value of the primary key is changed, that is, updated, the value of the foreign key must immediately be changed to match it. Cascading updates will set this change to be done automatically by the DBMS whenever necessary

What is PL/SQL?

PL/SQL is Oracle's Procedural Language extension to SQL. The language includes object oriented programming techniques such as encapsulation, function overloading, information hiding (all but inheritance), and so, brings state-of-the-art programming to the Oracle database server and a variety of Oracle tools

What is a Candidate Key?

A table may have more than one combination of columns that could uniquely identify the rows in a table, each combination is a Candidate Key

Difference betwween UNION and UNION ALL

UNION will remove the duplicate rows from the result set while UNION ALL does not.

Difference between TRUNCATE and DELETE



  • Both result in deleting of the rows in the table
  • TRUNCATE call cannot be rolled back  and all memory space for that table is released back to the server while DELETE call can be rolled back
  • TRUNCATE call is DDL command while DELETE call is DML command
  • TRUNCATE call is faster than DELETE call

Friday 18 July 2014

Difference between value types and reference types.


Following are the differences between value types and reference types in C#:

  • Value types are stored on the stack where as reference types are stored on the managed heap
  • Value type variables directly contain their values where as reference variables holds only a reference to the location of the object that is created on the managed heap
  • There is no heap allocation or garbage collection overhead for value-type variables. As reference types are stored on the managed heap, they have the over head of object allocation and garbage collection
  • Value types cannot inherit from another class or struct. Value types can only inherit from interfaces. Reference types can inherit from another class or interface 

Thursday 17 July 2014

Types of comments

There are three types of comments in c#:

  1. Single line(//)
//This is a single line comment

  1. Multi line(/*   */)
/*  This is a 
multi line comment */

  1. Page/XML(///)
/// This is an XML comment

What are the types of Authentication?


There are three types of Authentication:

  1. Windows Authentication: uses the security features integrated into the Windows NT and Windows XP operating system to authenticate and authorize web application users
  2. Forms Authentication: allows you to create your own list/database of users and validate the identity of those users when they visit your web site
  3. Passport Authentication: uses the Microsoft centralized authentication provider to identify users. Passport provides a way to for users to use a single identity across multiple web applications. To use Passport Authentication in your Web application, you must install the Passport SDK

For what purpose Global.asax file used?


It executes application-level events and sets application-level variables.

What is garbage collection?


It is a system where a run-time component takes responsibility for managing the lifetime of objects and the heap memory that they occupy. 

Serialization and Deserialization

Serialization is the process of converting an object into a stream of bytes.
De-serialization is the process of creating an object from a stream of bytes.

Both these processes are usually used to transport objects.

How to create a permanent cookie?


Permanent cookies are stored on the hard disk and are available until a specified date is reached.

  • To create a cookie that never expires set its Expires property equal to:
                            DateTime.MaxValue

What is difference between Classic ASP and ASP.NET?


ASP

  • ASP is interpreted language based on scripting languages like JScript or VBScript.
  • ASP has mixed HTML and coding logic
  • Limited development and debugging tools available
  • Limited OOPS support
  • Limited session and application state management


ASP.NET

  • ASP.NET is supported by compiler and has compiled language support
  • Separate code and design logic is possible
  • Variety of compilers and tools available including the Visual studio.NET
  • Completely Object Oriented
  • Complete session and application state management 
  • Full XML support for easy data exchange

Major built in objects in ASP.NET

The major built in objects in ASP.NET are:

  • Application
  • Context
  • Request 
  • Response
  • Server
  • Session
  • Trace

Authentication and Authorisation


Authentication
Authentication is the process of verifying the identity of a user using some credentials like username and password. Authentication merely ensures that the individual is who he or she claims to be, but says nothing about the access rights of the individual.

Authorization
The process of granting or denying access to a network resource.  Authorization determines the parts of the system to which a particular identity has access. 

Authentication is required before Authorization.

For e.g. If an employee authenticates himself with his credentials on a system, authorization will determine if he has the control over just publishing the content or also editing it

Turn Off cookies on one page of your website

This can be done by using the Cookie.Discard property:

  • It gets or sets the discard flag set by the server
  • It can be true or false. When set to true, this property instructs the client application not to save the Cookie on the hard disk of the user at the end of the session 

Wednesday 16 July 2014

ALGOL COBOL

ALGOL stands for ALGOrithimic Language

COBOL stands for COmnon Business Oriented Language 

Features of OOPS

Features of OOPS are:

  1. Abstraction 
  2. Encapsulation 
  3. Inheritance 
  4. Modularity 
  5. Polymorphism 

Tuesday 15 July 2014

Origin of C

C is a programming language developed at AT & T's Bell Laboratories of USA in 1972. It was designed and written by Dennis Ritchie.
Possibly why C seems so popular is because it is reliable, simple and easy to use.

When we mention the prototype of a function are we defining the function or declaring it?

We are declaring it. When the function, along with the statements belonging to it is mentioned, we are defining the function.

What are the differences between a declaration and a definition?

There are two differences between a declaration and a definition:

  1. In the definition of a variable space is reserved for the variable and some initial value is given to it, whereas a declaration identifies the type of the variable.
  2. Redefinition is an error, whereas, redeclaration is not an error.
Example of Definition:
int a=10;
char  ch='A';

Example of Declaration:
extern int a;
extern char ch;

What are portable programs?

Portable programs are the programs that would be compiled successfully by different compilers without any need to make changes in the program to suit a particular compiler.
Though hundred percent probability may not always be possible, it is good idea to reduce compiler dependencies to the extent possible

Device Drivers and Embedded Systems are created in C

Device Drivers and Embedded Systems are created in C. Also major part of popular operating system like Windows, UNIX, LINUX are still written in C. This is because even today when it comes to performance(speed of execution) nothing beats C. The programs on Embedded systems not only have to run fast but also have to work in limited amount of memory, and are written in C

What is a Programming Paradigm?

Programming Paradigm means the principle that is used for organizing programs. There are two major Programming Paradigms:

  1. Structured Programming
  2. Object Oriented Programming(OOP)

C language uses the Structured Programming Paradigm, whereas, C++, C#, VB.NET or Java make use of OOP
 

Monday 14 July 2014

How to allow textbox to type only digits?


Follow these steps:

  1. Generate KeyPress event for textbox by going into properties>>event, and then double click in front of KeyPress. Event will be automatically generated

  1. Now write this code in generated event:
if(!(char.IsDigit(e.KeyChar)))
       e.Handled=true;

e.KeyChar is character corresponding to key pressed
char.IsDigit( ) is a function whose return value is bool, it accepts one character and if character is digit it returns true otherwise false
e.Handled sets the value indicating whether a event is handled or not 
e.Handled=true;  means this event is handled i.e. the pressed key will be disabled, so the the character will not be shown in text-box

Note: If you are using above code only digits are allowed, you cannot use backspace as all other keys are handled i.e. disabled. For avoiding this use the following code instead of above code:

 if (!(char.IsDigit(e.KeyChar)||e.KeyChar ==(char )Keys.Back  ))

                e.Handled = true;
            
Now if key pressed is digit or backspace it will not be handled i.e. disable otherwise it will be handle


How to export data grid view to xps file?


To export data grid view to excel file follow these steps:

  1. Write a function export( ) as:

 private void export(string filename, string type)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + filename);
            Response.Charset = "";
            Response.ContentType = type;
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);      //render the gridview 
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.Close();
            Response.End();


        }

here name of our grid view is GridView1  so we have used GridView1.RenderControl(hw);
  1. Write public override void and select  VerifyRenderingInServerForm(Control control) from intelisense, function will displayed as:
 public override void VerifyRenderingInServerForm(Control control)
        {
            base.VerifyRenderingInServerForm(control);
        }

Now comment the line in function as:

public override void VerifyRenderingInServerForm(Control control)
        {
          //  base.VerifyRenderingInServerForm(control);
        }


We have done this for rendering of data grid view


  1. Now call the function export( )  on button_click( ) as:
export("myfile.xps","application/vnd.ms-xpsdocument");

the file will be saved as myfile.xps  you can specify other name for file also.

How to export data grid view to pdf file?


To export data grid view to excel file follow these steps:

  1. Write a function export( ) as:

 private void export(string filename, string type)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + filename);
            Response.Charset = "";
            Response.ContentType = type;
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);      //render the gridview 
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.Close();
            Response.End();


        }

here name of our grid view is GridView1  so we have used GridView1.RenderControl(hw);
  1. Write public override void and select  VerifyRenderingInServerForm(Control control) from intelisense, function will displayed as:
 public override void VerifyRenderingInServerForm(Control control)
        {
            base.VerifyRenderingInServerForm(control);
        }

Now comment the line in function as:

public override void VerifyRenderingInServerForm(Control control)
        {
          //  base.VerifyRenderingInServerForm(control);
        }


We have done this for rendering of data grid view


  1. Now call the function export( )  on button_click( ) as:
export("myfile.pdf","application/pdf");

the file will be saved as myfile.pdf  you can specify other name for file also.

How to export data grid view to doc file?


To export data grid view to excel file follow these steps:

  1. Write a function export( ) as:

 private void export(string filename, string type)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + filename);
            Response.Charset = "";
            Response.ContentType = type;
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);      //render the gridview 
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.Close();
            Response.End();


        }

here name of our grid view is GridView1  so we have used GridView1.RenderControl(hw);
  1. Write public override void and select  VerifyRenderingInServerForm(Control control) from intelisense, function will displayed as:
 public override void VerifyRenderingInServerForm(Control control)
        {
            base.VerifyRenderingInServerForm(control);
        }

Now comment the line in function as:

public override void VerifyRenderingInServerForm(Control control)
        {
          //  base.VerifyRenderingInServerForm(control);
        }


We have done this for rendering of data grid view


  1. Now call the function export( )  on button_click( ) as:
export("myfile.doc","application/msword");

the file will be saved as myfile.doc you can specify other name for file also.

for exporting to .docx file use "application/vnd.openxmlformats-officedocument.wordprocessingml.document" instead of "application/msword" and change the file extension as "myfile.docx"

How to export data grid view to excel file?


To export data grid view to excel file follow these steps:

  1. Write a function export( ) as:

 private void export(string filename, string type)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + filename);
            Response.Charset = "";
            Response.ContentType = type;
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);      //render the gridview 
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.Close();
            Response.End();


        }

here name of our grid view is GridView1  so we have used GridView1.RenderControl(hw);
  1. Write public override void and select  VerifyRenderingInServerForm(Control control) from intelisense, function will displayed as:
 public override void VerifyRenderingInServerForm(Control control)
        {
            base.VerifyRenderingInServerForm(control);
        }

Now comment the line in function as:

public override void VerifyRenderingInServerForm(Control control)
        {
          //  base.VerifyRenderingInServerForm(control);
        }


We have done this for rendering of data grid view


  1. Now call the function export( )  on button_click( ) as:
export("myfile.xls","application/vnd.ms-excel");

the file will be saved as myfile.xls  you can specify other name for file also.

for exporting to .xlsx file use "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" instead of "application/vnd.ms-excel" and change the file extension as "myfile.xlsx"

Sunday 13 July 2014

How to add speech or voice to your project?


Follow these steps:
  1. Add reference "System.Speech" from Assemblies >> Framework tab. To know how to add reference to your project click: http://gsbprogramming.blogspot.in/2014/07/how-to-add-reference-to-your-project-in.html
  2. Add namespace:    Using System.Speech.Synthesis;
  3. Create object of SpeechSynthesizer as:
SpeechSynthesizer reader=new SpeechSynthesizer( );

  1. Now use "reader" object to enable speech as:
 reader.Speak("message");

or

reader.SpeakAsync("message");

replace message with whatever you want to speak

Difference between reader.Speak( )   and reader.SpeakAsync( )  is that reader.Speak( ) will speak synchronously i.e. when speaking is finished only then next statements will execute while in reader.SpeakAsync( ) speaking is asynchronously i.e. speaking will be carried out on background and next statements can be executed simultaneously .


Note:  If  you are using reader.SpeakAsync( ) on button click then please use :
reader.Dispose( );
reader=new SpeechSynthesizer( );
and then
reader.SpeakAsync("message");

because when your click the button more than once continously speaking will be continued as many time as user has clicked the button
so to avoid this please use above .

How to capture a screen shot of screen?


To capture screen shot write a funtion:

 Bitmap  getScreen( )
        {
            Size s = Screen.PrimaryScreen.Bounds.Size;   //gives the screen size
            Bitmap bt = new Bitmap(s.Width, s.Height);   //create object of Bitmap with screen size
            Graphics g = Graphics.FromImage(bt);
            g.CopyFromScreen(0, 0, 0, 0, s);
            return bt;
        }

now you can assign the captured screen to picture box as:
pictureBox1.Image=getScreen( );

What is use of partial keyword?


partial keyword allows you to split the definition of one class into multiple files.
For Example: When you open a project the default form has following defintion:
 public partial class Form1 : Form

this allow the definition of class Form1 to split into multiple files  i.e.  Form1.cs and Form1.Designer.cs
hence the members of Form1 can be used in Form1.Designer.cs

How to save picture box image?


To save image of a picture box use the following syntax:

pictureBox1.Image.Save("path");

For example:

pictureBox1.Image.Save(@"d:\pic.jpg");

here name of picture box is  pictureBox1 and image will be saved in d:\ drive and "pic.jpg" will be the name of your image

Saturday 12 July 2014

What are DQL statements?

DQL(Data Query Language) statement is used to query data from the database.
  • SELECT- used to get rows and/or columns from tables or views

What are Embedded SQL statements?


Embedded SQL statements are used to incorporate DDL, DML and TCL statements within the body of a procedural language program. These are:
  • DEFINE- used to define cursors
  • OPEN-  used to allocate cursors
  • DECLARE- used to assign variable names
  • EXECUTE- used to execute SQL statements
  • FETCH- used to retrieve data from database

What are TCL statements?

TCL(Transaction Control Language) statements manage the change made by DML statements, and group DML statements into transactions. These are:
  • COMMIT- used to make a transaction's changes permanent
  • ROLLBACK- used to undo changes in a transaction, either since the transaction started or since a savepoint
  • SAVEPOINT- used to set point to which a transaction can be rolled back
  • SET TRANSACTION- used to establish properties for a transaction

What are DCL statements?


DCL(Data Control Language) are used to grant or revoke privileges from a user. These are:
  • GRANT- used to grant a privilege
  • REVOKE- used to revoke a privilege
  • COMMENT- used to add a comment to the data dictionary

What are DML statements?


DML(Data Manipulation Language) statements enable users to query or manipulate data in existing schema objects. These are:
  • DELETE- used to remove rows from tables or views
  • INSERT- used to add new rows of data into tables or views
  • SELECT- used to retrieve data from one or more tables
  • UPDATE- used to change column values in existing rows of a table or view

What are DDL statements?


DDL (Data Defintion Language) are those statements which are used to define, alter, or drop database objects. These are:
  • CREATE- used to create schema objects
  • ALTER- used to alter schema objects
  • DROP- used to delete schema objects
  • RENAME- used to rename schema objects

What are various categories or statements in SQL?


Oracle divides SQL statements into various categories, which are:
  • DDL (Data Definition Language)
  • DML (Data Manipulation Language)
  • DCL (Data Control Language)
  • TCL (Transaction Control Language)
  • Embedded SQL statements

What is SQL?


SQL stands for Structured Query Language. SQL is a simple and powerful language used to create, access, and manipulate data and structure in a database. SQL is like plain English, easy to understand and write. SQL is a non-procedural language.
Features of SQL:
  1. Easy to read and understand.
  2. Can be used by those having little or no programming experience.
  3. It is a non-procedural language.
  4. It is based upon relational algebra and relational tuple calculus.

SQL was designed by Donald D. Chamberlin and Raymond F. Boyce. 

How to import excel sheet in your project in C#?

Follow these steps:


  • Add namespace : Using System.Data.Oledb;
  • Define the path of your Excel file as
string path="Provider=Microsoft.Ace.OLEDB.12.0; Data Source="+"path"+"; Extended Properties=\"Excel 8.0; HDR=Yes;\";";  
For Example
string path="Provider=Microsoft.Ace.OLEDB.12.0; Data Source="+"d:\\list.xlsx"+"; Extended Properties=\"Excel 8.0; HDR=Yes;\";";

Provider=Microsoft.Ace.OLEDB.12.0;  is used as provider name for excel sheet (.xlsx)
Data Source="+"d:\\list.xlsx"+";  tells the path of excel file (Here file is in d drive named as list.xlsx, to show \ we have to use \\)
HDR=Yes; tells that first row of excel sheet will be header in gridview.

  •  Define Oledb connection and Oledb command as:
 OleDbConnection  conn = new OleDbConnection(path); 
 OleDbCommand  cmd= new  OleDbCommand("Select * from[" + "sheet1" + "$]", conn);

Here we have used sheet1 of excel file list.xlsx. 
If you have sheet named as mysheet, then you will weite "mysheet" instead of   "sheet1".
"Select * from[" + "sheet1" + "$]" will select all data from excel sheet whose location is specified by conn

  •  Now we require  OleDbDataReader to store the result of  cmd i.e. OleDbCommand as:
 OleDbDataReader odr = cmd.ExecuteReader( ); 
This will store all data of select command in odr.
ExceuteReader( ) is used when we used a select query.


  • Now assign this datasource i.e. odr to Data Grid View like:
dataGridView1.DataSource = odr;

for asp.net  add another statement:

dataGridView1.DataBind( );


This will show the entire excel sheet's data in grid view.




How to add reference to your project in c#?

Follow these steps:

  1. Open Solution Explorer.
  2. Right click your project name or right click "References" folder in your project.
  3. Click on "Add Reference".
  4. Reference Manager dialog box will appear.
  5. Select any tab from left and select the reference.
  6. If you have downloaded the dll file and want to add it in your project then click browse button and then select the location of file.
  7. Click the Add button 
  8. Reference will be added to your project.

How to start a process or an application?

To start any process or application use the following syntax:

System.Diagnostics.Process.Start("path");
For example:
System.Diagnostics.Process.Start(@"d:\myapp.exe");  //open myapp.exe


How to update album art of an mp3 file?

Follow these steps:


  1. Download C# ID3 library from internet or use "http://sourceforge.net/projects/csid3lib/files/csid3lib/"  (Click Download csid3lib-v0.6-src.zip (3.3 MB) ) .
  2. Once you have downloaded the file,extract it and open id3lib.sln and and rebuild the solution.
  3. Now click start button to start debugging.
  4. After that start a new project(C#) and add a window form.
  5. Right click your project solution and click "add reference".
  6. Now click Browse button .
  7. Goto "C:\csid3lib-v0.6-src \id3lib\Mp3Lib\bin\Release" (Here i have extract the zip file in c:\ drive) and select these three files: "Id3Lib.dll", "Mp3Lib.dll", "ICSharpCode.SharpZipLib.dll" 
  8. Now you have added the dll files and can use it.
  9. Now to update album art of an mp3 file use the following code:
Mp3Lib.Mp3File file=new Mp3Lib.Mp3File(@"f:\AASHIQ.mp3");  //give the path of mp3 file
file.TagHandler.Picture=Image.FromFile(@"f:\pic1.jpg");   //give the path of image
file.Update();   

This will change the album art

How to extract information like artist, album, comments, album art from mp3 file?

Follow these steps

  1. Download C# ID3 library from internet or use "http://sourceforge.net/projects/csid3lib/files/csid3lib/"  (Click Download csid3lib-v0.6-src.zip (3.3 MB) ) .
  2. Once you have downloaded the file,extract it and open id3lib.sln and and rebuild the solution.
  3. Now click start button to start debugging.
  4. After that start a new project(C#) and add a window form.
  5. Right click your project solution and click "add reference".
  6. Now click Browse button .
  7. Goto "C:\csid3lib-v0.6-src \id3lib\Mp3Lib\bin\Release" (Here i have extract the zip file in c:\ drive) and select these three files: "Id3Lib.dll", "Mp3Lib.dll", "ICSharpCode.SharpZipLib.dll" 
  8. Now you have added the dll files and can use it.
  9. Now to extract the information from mp3 file use following code:
 Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(@"f:\AASHIQ.mp3");   //give the path of mp3 file.

tbAlbum.Text=file.TagHandler.Album;  //get the album of mp3 file

other properties of file.TagHandler are:
 file.TagHandler.Artist;
            file.TagHandler.Comment;
            file.TagHandler.Composer;
            file.TagHandler.Disc;
            file.TagHandler.Genre;
            file.TagHandler.Lyrics;
            file.TagHandler.Picture;
            file.TagHandler.Title;
            file.TagHandler.Track;
            file.TagHandler.Year;

Thanks...
Please comment...