Sunday, May 24, 2015

Visual Studio 2012, 2013, 2015 and ASP.NET Web Configuration Tool

Run this command in console(cmd)
"C:\Program Files\IIS Express\iisexpress.exe" /path:c:\windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/asp.netwebadminfiles" /port:8089 /clr:4.0 /ntlm
Than open your browser and open this url http://localhost:8089/asp.netwebadminfiles/default.aspx?applicationPhysicalPath=[Exact_Project_Path]\&applicationUrl=/ 
Also make sure you have this connection string in your web.config file
<connectionStrings>
    <clear/>
    <add name="LocalSQLServer" connectionString="......." providerName="System.Data.SqlClient"/>
  </connectionStrings>
<clear> is important

Tuesday, May 19, 2015

LINQ: SqlDateTime overflow. Must be between ...

WHEN a NULL value to passed to a non null datetime field using LINQ datasource. If the field is autogenerated make sure to mark as autogenerated in LINQ DBML designer else pass the value using a parameter

Thursday, May 14, 2015

Get all asp net listview items in array

var rows = [];
$('#<%: lvStudents.ClientID %>_itemPlaceholderContainer tr:gt(1)').each(function (i, v) {
    var row = $(this);
    rows.push(row);
});
if InsertItemPosition="LastItem"
gt(1)
else if InsertItemPosition="FirstItem" 
gt(2)

Skip first N elements in JQuery

jQuery has a gt selector. (Greater than).
$('#test > div:gt(1)');
Or you can use the slice function
$('#test > div').slice(2);

Wednesday, May 13, 2015

How to update rows randomly

update dbo.Table 
set Field = Value 
where Id in ( select top 50 percent id from dbo.Table order by NEWID() )

Handling Multiple FULL OUTER JOIN in sql

SELECT A.column2 , B.column2 , C.column2 FROM ( 
 (SELECT month, column2 FROM table1) 

 FULL OUTER JOIN 
 (SELECT month, column2 FROM table2) 
B on A.month= B.month 
 FULL OUTER JOIN 
 (SELECT month, column2 FROM table3) 
C on ISNULL(A.month, B.month) = C.month )

How to update rows with a random date

UPDATE table SET datetimecol = DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0)

How to convert IList to IQuerable

IQueryable query = new List() { 1, 2, 3, 4, 5}.AsQueryable();

How to check if IQueryable result set is null or empty

list will never be null with LINQ; it will simply represent an "empty collection" if need be. The way to test is with the Any extension method:
if (list.Any()) 
{
// list has at least one item
}

What “exec sp_reset_connection” shown in Sql Profiler means?

sp_reset_connection indicates that connection pool is being reused

Saturday, May 9, 2015

Disabling Chrome, Firefox, Safari, Opera, IE Autofill

<form>
<!-- fake fields are a workaround for chrome autofill getting the wrong fields -->
<input style="displaynone" type="text" name="fakeusernameremembered" />
<input style="displaynone" type="password" name="fakepasswordremembered" />
</form>

Friday, May 8, 2015

Value cannot be null. Parameter name: panelsCreated[0] asp net

Switch scriptmanager mode to release

<asp:ScriptManager runat="server" ScriptMode="Release" />

InvalidOperationException: Could not find UpdatePanel with ID asp net

Change ClientIDMode on UpdatePanels to AutoID

<asp:UpdatePanel runat="server" ClientIDMode="AutoID">

Monday, May 4, 2015

Friday, May 1, 2015

How to disable/enable buttons and links (jQuery + Bootstrap)

jQuery.fn.extend({
   disable: function (state) {
      return this.each(function () {
         var $this = jQuery(this);
         if ($this.is('input, button'))
            this.disabled = state;
         else if($this.is('a'))
            $this.toggleClass('disabled', state);
      });
   }
});