Wednesday 15 May 2013

how to fix "The file xxxx.aspx has not been precompiled and cannot be requested" error?

how to fix "The file xxxx.aspx has not been precompiled and cannot be requested" error?

If you try to access an aspx you may have experienced with the error

"The file xxxx.aspx has not been precompiled and cannot be requested".

This error is purely related with missing assemblies in the page. Check what are all the assemblies used in the page and ensure that those are in web.config and GAC or some times in the bin folder.






Thursday 28 February 2013

How to Select Major Cities on Top in SQL?

How to Select Metro Cities on Top in SQL?

In this article, we are going to see how to select the cities on top of the list in SQL i.e. metro cities like, Delhi, Mumbai, Kolkata, Chennai Should come on top rest of the cities come below. Here is the query


Select City_Name from City Where City_Name in ('Delhi','Mumbai','Kolkata','Chennai')
union all
Select City_Name from City Where City_Name not in ('Delhi','Mumbai','Kolkata','Chennai')


Below Image shows the result set



Monday 25 February 2013

How to loop through records without using cursor in SQL?

How to loop through records without using cursor in SQL?

In SQL, if we use cursors, performance will be hit, to avoid the performance issue, we can use while loop with temporary tables.

First insert the records you want process into a temporary table and for example, here we can print the records one by one


Use Northwind
declare @ProdID int
declare @ProductName Varchar(200)

Set NOCOUNT on

Begin

Select top 10 * into #temp from products order by ProductID

While (Select COUNT(*) from #temp)>0

Begin

Select @ProdID=ProductID, @ProductName=ProductName  from #temp

Print @ProductName

Delete from #temp where ProductID=@ProdID

End

Drop table #temp
 End

Please click the sample below  to enlarge and view






Wednesday 20 February 2013

How to write error or exception Messages into Event log in C#?

How to write error or exception Messages into Event log in C#?

There are situations where we don't want to show the errors or exceptions to users, in that scenario,  we can write messages into Server's Event Log by using the below function for our debugging purpose

Please replace "YourProjectName" with your's Project Name


public void WriteErrorToEventLog(string strErrMsg)
{
 System.Diagnostics.EventLog objLog= new System.Diagnostics.EventLog();

 if (!EventLog.SourceExists("YourProjectName"))
  
        { EventLog.CreateEventSource("YourProjectName", "Application");}
objLog.WriteEntry("YourProjectName", strErrMsg, System.Diagnostics.EventLogEntryType.Error);
}


Enjoy!!

Saturday 16 February 2013

How to change dataview to datatable in C#?

There are situations, we have to convert a dataview to datatable as the code below.

Dataable dt=dv.ToTable();


Enjoy!!

You might also like:

Related Posts Plugin for WordPress, Blogger...