Interview answers verified by specialists.

Find interview questions and answers on this website:

See right interview answers on 30 common job interview questions

Describe the command object and its method.

After successful connection with database you must execute some sql query for manipulation of data or selecting the data. This job is done by command object. If you are using SQL Server as database then SqlCommand class will be used. It executes SQL statements and Stored Procedures against the data source specified in the Connection Object. It requires an instance of a Connection Object for executing the SQL statements. 

- ExecuteReader: This method works on select SQL query. It returns the DataReader object. Use DataReader read () method to retrieve the rows. 
- ExecuteScalar: This method returns single value. Its return type is Object 
- ExecuteNonQuery: If you are using Insert, Update or Delete SQL statement then use this method. Its return type is Integer (The number of affected records).

using System;
using System.Data;
using System.Data.SqlClient; 
public partial class Default2 : System.Web.UI.Page 
protected void Page_Load(object sender, EventArgs e) 
SqlConnection con = new SqlConnection("Data Source=Your data source name;Initial Catalog=Demo;Integrated Security=True"); 
SqlCommand cmd = new SqlCommand(); 
cmd.Connection = con; 
cmd.CommandText = "select * from employee"; 
cmd.CommandType = CommandType.Text; 
SqlDataReader reader = cmd.ExecuteReader(); 
if (reader.HasRows)
while (reader.Read())
Label1.Text="No rows found."; 

In the above given example a DropdownList has been taken that is filled by second column of employee table

Do you know that?

32.5% freelancers earn as more as they were full time employee in the same industry Next


Getting payments for Freelancers
1. Read how to register and get earned money

2. Open account within 5 minPayoneer sing up to get free $25