Wednesday 23 April 2014

value Labs Interview

value Labs Interview
1.Threading in .Net
2.windows services(About Timer)
3.How to call storedprocedure in Asp.Net with code.

private void BindGridView()
{
DataSet objDs = new DataSet();
System.Data.SqlClient.SqlConnection
myConnection = new SqlConnection(ConnectionString);
System.Data.SqlClient.SqlDataAdapter myCommand;
myCommand = new System.Data.SqlClient.SqlDataAdapter("sp_GridView_RowNumber", myConnection);
myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
// PageNum
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@PageNum", SqlDbType.Int, 4));
myCommand.SelectCommand.Parameters["@PageNum"].Value = PageNum;
// PageSize
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@PageSize", SqlDbType.Int, 4));
myCommand.SelectCommand.Parameters["@PageSize"].Value = PageSize;
// TotalRowsNum
SqlParameter TotalRowsNum = new SqlParameter("@TotalRowsNum", SqlDbType.Int);
TotalRowsNum.Value = null;
TotalRowsNum.Direction = ParameterDirection.Output;
myCommand.SelectCommand.Parameters.Add(TotalRowsNum);
myCommand.SelectCommand.Parameters["@TotalRowsNum"].Value = null;
myConnection.Open();
myCommand.Fill(objDs);
GridView1.DataSource = objDs;
GridView1.DataBind();
Navigation(Convert.ToInt32(TotalRowsNum.Value.ToString()));
}
private void Navigation(int totalRecords)
{
Double totalPages = Math.Ceiling(((double)totalRecords / PageSize));
if ((totalRecords == 1) || (totalPages == 0))
{
totalPages = 1;
}
if (PageSize > totalRecords)
{
PageSize = (int)totalPages;
}
GoToPageTxt.Text = PageNum.ToString();
CurrentPage.Text = PageNum.ToString();
TotalPages.Text = totalPages.ToString();
}
4.How to call GC explicitly.
Ans)By calling gc.Collect() we can call Garbage collector explicitly.
--------
GarbageCollector Gc = new GarbageCollector();
Gc.Collect();
------------------------------------
Ans)with the help of dispose( ) method u can call the garbage collecter explicitely

EX: obj.Dispose( )
where obj[--]>it can be any object
----------------
Calling Dispose method will only let Garbage collector knonw that a particular object is ready to be disposed but it will not call garbage collector explicitely.
I think gc.Collect() is the way.
----------------------------------------
using(DisposableClass dc = new DisposableClass())
{
dc.PerformActionOnUmanagedResources();
dc.PerformAnotherActionOnUmanagedResources();
}
In the above example, if an exception was thrown in the PerformActionOnUmanagedResources() method, although the PerformAnotherActionOnUmanagedResources() method would not be processed, the using block will still implicity invoke the Dispose method on dc ensuring the realese of any unmanaged resources.
-------------------------------------------------------------
5.Execute Scalar and nonquery.