Thursday, March 03, 2011

ASP.NET Ajax 3.5 error Sys.WebForms.PageRequestManagerParserErrorException

A few days ago, I wanted to add an Export to Excel button in a page in my web application, that I used Ajax on it, But unfortunately it did not work properly and generated an error(the same as my post header). After searching in the net I found out I have to add a line in page. That's it, it Worked excellent :). If you encountered this error, you must add:

EnableEventValidation="false"

and also:

        <Triggers>
            <asp:PostBackTrigger ControlID="ControlName" />
       </Triggers>


Good luck :)

Tuesday, April 20, 2010

Gridview Sorting Problem

When you bind a List to a Gridview, you can not sort it, because your data source is not a Dataset, Dataview or DataTable. So you should convert your data source (List) to a Dataset for example.


You can do it such as following code:


    1 public static DataSet dsSearch()
    2 {
    3 
    4     DataTable dtTelcoCenter = new DataTable();
    5     dtTelcoCenter.Columns.Add("Id", typeof(int));
    6     dtTelcoCenter.Columns.Add("City", typeof(string));
    7     dtTelcoCenter.Columns.Add("Capacity", typeof(int));
    8 
    9     IList<Telco> telcoCenter = Search(centerName, Prefix);// Search method return a list
   10 
   11 
   12     foreach (Telco telco in telcoCenter)
   13     {
   14         DataRow rowTelcoCenter = dtTelcoCenter.NewRow();
   15         rowTelcoCenter["Id"] = telco.Id;
   16         rowTelcoCenter["City"] = telco.City;
   17         rowTelcoCenter["Capacity"] = telco.Capacity;
   18         dtTelcoCenter.Rows.Add(rowTelcoCenter);
   19     }
   20     DataSet dsTelcoCenter = new DataSet();
   21     dsTelcoCenter.Tables.Add(dtTelcoCenter);
   22     return dsTelcoCenter;
   23 }

You can bind this Dataset to your Gridview data source

Rows to single column in Sql

Sample table as Cities in rows is convert to single column

declare @retstr varchar(8000)  
 select Top 5 @retstr =  COALESCE(@retstr + ';','') + City   
from State  
print @retstr  

Monday, January 04, 2010

How can you save a MS Office file into a database?

If you want to save a MS Office document such as 
Word doc in a database, you can do it with the 
following VB.net code:

    Dim vStream As New FileStream("C:\Alex.doc", FileMode.Open) 
    Dim vLen As Integer = New FileInfo("C:\Alex.doc").Length
    Dim vBlob(vLen) As Byte
    Dim n As Integer = vStream.Read(vBlob, 0, vLen)
    Dim vSql As String = 
"INSERT INTO tBlobTable (vId,vBlob) VALUES (1,@vBlob)" 
    Dim sql As New SqlCommand(vSql, vConn)
    Dim sqlPar As New SqlParameter("@vBlob", SqlDbType.Image)
    sqlPar.Value = vBlob
    sql.Parameters.Add(sqlPar) 

I hope you would find it useful.

Sunday, November 29, 2009

Parameter Sniffing

Sometimes maybe you find out your SP (Store Procedure) doesn't response in reasonable time despite Select statement, which you used in that SP, has good performance and result is shown you immediately. What's wrong with your SP?
There are different answers for that problem but when I faced on this problem, I realized it's strongly related to Parameter Sniffing.

You can solve Parameter Sniffing easily with follow this example:
If you have a SP such as GetOrderForCustomers that has Parameter Sniffing issue:

Create procedure GetOrderForCustomers (@CustID Varchar (20))
As
Begin
Select * from orders
Where customerid = @CustID
End

To solve problem you should change your SP similar:

Create procedure GetOrderForCustomers (@CustID Varchar (20))
As
Begin
Declare @LocCustID Varchar (20)
Set @LocCustID = @CustID
Select * from orders
Where customerid = @LocCustID
End

Good luck.

Wednesday, November 25, 2009

How to Speed up SQL Server Management Studio in SQL Server 2005?

Have you ever launched SQL Server Management Studio (SSMS) and had to wait over 60 seconds before you could even log in? I have - all too often! It's annoying - and thankfully there's an easy fix.
  1. Launch Internet Explorer
  2. Browse to Tools -> Internet options -> Advanced tab
  3. Uncheck the check box under Security called "Check for publisher's certificate revocation"
Now you'll be able to launch SSMS and it will be fast. BTW - this works particularly well for offline workstations/laptops. When you are connected to the internet and SSMS checks for this info (every 15 friggin' seconds) then it's fine - but when you aren't online, it has to wait for a timeout!

Monday, November 23, 2009

Increase your VS compile speed

To increase your VS compile speed:
  • Install Microsoft hotfix 935225.
  • Install Microsoft hotfix 947315.
  • Use a true multicore processor (ie. an Intel Core Duo 2; not a Pentium 4 HT).
  • Use 3 parallel builds. In Visual Studio 2005, you will find the option in Tools > Options... > Projects and Solutions > Build and Run > maximum number of parallel project builds.
  • Defragment your hard drive regularly.
  • Disable virtual memory.

Sunday, November 15, 2009

Visual studio IDE

Visual studio is a pretty awesome IDE, but sometimes you just wish it would go faster.


Here's a list. All of these can be accessed on Tools->Options menu:
  1. Disable F1. (Environment->Keyboard) This is probably the best advice that I found somewhere.
  2. Disable "Animate environment tools" (Environment->General).
  3. Disable Start Page (Environment->Startup).
  4. Disable "Track Active Item in Solution Explorer" (Projects and Solutions).
  5. Disable Navigation Bar (Text Editor->C#). I think this is available for every language.
  6. Set "AutoToolboxPopulate" to false (Windows Forms Designer).
  7. You can set the Code view as the default view when viewing Windows Forms. Just right-click on the cs file and select "Open With...".
  8. Open Visual Studio using the command line (devenv) rather than using the Start menu. I don't know why but I notice it loads faster.
  9. Turn off Track Changes. (Text Editor->Track changes)
Basically I just customized John Lam's settings. It's very minimal.


And also you can use ScottGu's Blog tips.