Wednesday 30 March 2016

Excel - Add new line in formula

Watch this example on YouTube

 

="Select * From Employee " & CHAR(10) & "  GO"

Excel - Fix the following error - Error in Value

Watch this example on YouTube

Replace
="Select * From Employee "  + CHAR(10) + "GO"

With
="Select * From Employee "  & CHAR(10) & "GO"

MVC - create read only textbox

Watch this example on YouTube


 @Html.TextBox(Model.CustomerLastName, Model.CustomerLastName, new { @readonly = "readonly" })

MVC - Button - Move to another page - with no validation

Watch this example on YouTube


<input type="submit" onclick="location.href='@Url.Action("Index", "Home")'" value="go to another page" />

Tuesday 29 March 2016

Excel - Add text to the formula

Watch this example on YouTube

=A1 & " ONE"

MVC - Fix the following error: The current request for action 'Index' on controller type '' is ambiguous between the following action methods:


Watch this example on YouTube:


The current request for action 'Index' on controller type '' is ambiguous between the following action methods:

To fix it replace
      public ActionResult Index(Customer model)
        {
            return View(db.Customers.ToList());
        }

with
      [HttpPost]
      public ActionResult Index(Customer model)
        {
            return View(db.Customers.ToList());
        }

MVC - ActionLink with PostBack

Watch this example on YouTube
1. Add the following to _Layout file
        @Scripts.Render("~/Scripts/jquery-1.8.2.min.js")
        @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.js")
    </head>

2. create Action Link in View:
@Ajax.ActionLink("RecordID", "Index", new AjaxOptions { HttpMethod = "POST"})

3. create new method in Controller that will respond to postback
        [HttpPost]
        public ActionResult Index(Customer model)
        {
            return View(db.Customers.ToList());
        }

MSSQL - Declare OUTPUT parameters inside Stored Procedure


Watch this example on YouTube:

1. Here is my first sp:
CREATE PROCEDURE [dbo].[TestOutput_Procedure1]
    @Success int = 0 Output
AS
BEGIN
    SET NOCOUNT ON;

    SET @Success = 1;
    Return @Success;
END

2. Second one
CREATE PROCEDURE [dbo].[TestOutput_Procedure2]
AS
BEGIN
    SET NOCOUNT ON;

    Declare @Success int = 0;
    Exec TestOutput_Procedure1 @Success OUTPUT;
    Select @Success;
END

3. Test
Exec TestOutput_Procedure2;

Monday 28 March 2016

JavaScript - fix the following error 0x800a138f - JavaScript runtime error: Unable to get property 'checked' of undefined or null reference

Watch this example on YouTube

JavaScript - fix the following error
0x800a138f - JavaScript runtime error: Unable to get property 'checked' of undefined or null reference

Replace
                var One = document.getElementById('rbOne');
                var Two = document.getElementById('rbTwo');    
                if (One[0].checked) {
With
                var One = document.getElementById('<%= rbOne.ClientID %>');
                var Two = document.getElementById('<%= rbTwo.ClientID %>');    
                if (One.checked) {

Fix the following error: The variable name '@return_value' has already been declared. Variable names must be unique within a query batch or stored procedure.


Watch this example on YouTube
In order to fix it
replace
DECLARE    @return_value int,        @Success int
EXEC    @return_value = [dbo].[GetAllCustomers] @Success = @Success OUTPUT
SELECT    @Success as N'@Success' SELECT    'Return Value' = @return_value

DECLARE    @return_value int,        @Success int
EXEC    @return_value = [dbo].[GetAllCustomers] @Success = @Success OUTPUT
SELECT    @Success as N'@Success' SELECT    'Return Value' = @return_value

With
DECLARE    @return_value int,        @Success int
EXEC    @return_value = [dbo].[GetAllCustomers] @Success = @Success OUTPUT
SELECT    @Success as N'@Success' SELECT    'Return Value' = @return_value
GO

DECLARE    @return_value int,        @Success int
EXEC    @return_value = [dbo].[GetAllCustomers] @Success = @Success OUTPUT
SELECT    @Success as N'@Success' SELECT    'Return Value' = @return_value
GO

MSSQL - Reset Identity

Watch this example on YouTube:

DBCC CHECKIDENT('TableName', RESEED, 0)

Friday 25 March 2016

MSSQL - List definitions of very long stored procedures


Watch this example on YouTube:



SELECT ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_DEFINITION AS FIRST4000,
OBJECT_DEFINITION(Object_ID(ROUTINE_NAME)) AS FULLDefinition,
LEN(OBJECT_DEFINITION(OBJECT_ID(ROUTINE_NAME))) AS LenOfTheObject
FROM INFORMATION_SCHEMA.ROUTINES
WHERE (LEN(OBJECT_DEFINITION(OBJECT_ID(ROUTINE_NAME)))> 4000)
ORDER BY LenOfTheObject


Fix the following error: The type or namespace name 'MethodInfo' could not be found (are you missing a using directive or an assembly reference?)

Watch this example on YouTube:

Fix the following error:
The type or namespace name 'MethodInfo' could not be found (are you missing a using directive or an assembly reference?)

Replace:
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
With:
public override bool IsValidName(ControllerContext controllerContext, string actionName, System.Reflection.MethodInfo methodInfo)

Fix the following error: The type or namespace name 'SelectListItem' could not be found (are you missing a using directive or an assembly reference?)

Watch this example on YouTube:

The type or namespace name 'SelectListItem' could not be found (are you missing a using directive or an assembly reference?) 

Add the following using:

using System.Web.Mvc;

MVC - Fix the following error: The name 'DateTimeFormatInfo' does not exist in the current context


Watch this example on YouTube:

Add the following
using System.Globalization;

MVC - Fix the following error: 0x800a1391 - JavaScript runtime error: 'jQuery' is undefined


Watch this example on YouTube:


in order to fix
0x800a1391 - JavaScript runtime error: 'jQuery' is undefined

in _Layout file replace:
        @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.js")
    </head>

with

        @Scripts.Render("~/Scripts/jquery-1.8.2.min.js")
        @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.js")
    </head>