Watch this example on YouTube
SELECT * INTO NewTable FROM ExisitngTable
Tuesday, 21 November 2017
MSSQL - How to add new integer column to the table with default value
Watch this example on YouTube
ALTER TABLE table_name
ADD IntegerColumn int NOT NULL DEFAULT(123)
ALTER TABLE table_name
ADD IntegerColumn int NOT NULL DEFAULT(123)
Saturday, 18 November 2017
MSSQL - Fix Error - Conversion failed when converting the varchar value ' ID is set to: ' to data type int.
Error
Conversion failed when converting the varchar value ' ID is set to: ' to data type int.
Watch solution on YouTube
to fix it replace
Declare @id int = 10
print ' ID is set to: ' + @id
with
Declare @id int = 10
print ' ID is set to: ' + CAST(@id As Varchar)
Conversion failed when converting the varchar value ' ID is set to: ' to data type int.
Watch solution on YouTube
to fix it replace
Declare @id int = 10
print ' ID is set to: ' + @id
with
Declare @id int = 10
print ' ID is set to: ' + CAST(@id As Varchar)
MSSQL - Microsoft SQL Server Management Studio - How to increase font size
Watch on YouTube
Goto Tools->Options->Environment->Fonts and Colors
Goto Tools->Options->Environment->Fonts and Colors
MSSQL - Fix Error - Incorrect syntax near '='
Watch this example on YouTube
To fix it replace
Declare @test int = 0
if(@test == 0)
begin
print 'Zero'
end
with
Declare @test int = 0
if(@test = 0)
begin
print 'Zero'
end
To fix it replace
Declare @test int = 0
if(@test == 0)
begin
print 'Zero'
end
with
Declare @test int = 0
if(@test = 0)
begin
print 'Zero'
end
Saturday, 11 November 2017
MSSQL - list recently modified tables
Watch on YouTube
Select * From sys.tables order by modify_date desc
MSSQL - List recently created stored procedures
Watch on YouTube
Select name, create_date, modify_date
From sys.objects
Where (type='P')
Order by create_date desc
MSSQL - Load recently modified stored procedures
watch this example on YouTube
select name , create_date, modify_date
from sys.objects
where type='P'
order by modify_date desc
select name , create_date, modify_date
from sys.objects
where type='P'
order by modify_date desc
Saturday, 4 November 2017
MVC - fix error - Unable to cast object of type 'System.Int32' to type 'System.String'."
Watch on YouTube
How to set max length of integer
1. Metadata file
namespace MVCValidationTest.Models
{
[MetadataType(typeof(SelectTestValidation_Metadata))]
public partial class SelectTestValidation_Result
{
//[StringLength(3, ErrorMessage = "{0} cannot be longer than 3 chars")]
[Range(1,999)]
public int test { get; set; }
2. View
@Html.TextBoxFor(x => x.test, new { maxlength = 3 })
How to set max length of integer
1. Metadata file
namespace MVCValidationTest.Models
{
[MetadataType(typeof(SelectTestValidation_Metadata))]
public partial class SelectTestValidation_Result
{
//[StringLength(3, ErrorMessage = "{0} cannot be longer than 3 chars")]
[Range(1,999)]
public int test { get; set; }
2. View
@Html.TextBoxFor(x => x.test, new { maxlength = 3 })
MSSQL - How to fix error - Incorrect syntax near '='.
Watch this example on YouTube
To fix it replcae
Declare @temp int = 2;
if @temp == 2
Begin
print ('found')
End
Else
Begin
print ('not found')
End
with
Declare @temp int = 2;
if @temp = 2
Begin
print ('found')
End
Else
Begin
print ('not found')
End
To fix it replcae
Declare @temp int = 2;
if @temp == 2
Begin
print ('found')
End
Else
Begin
print ('not found')
End
with
Declare @temp int = 2;
if @temp = 2
Begin
print ('found')
End
Else
Begin
print ('not found')
End
Thursday, 2 November 2017
MVC - How to add MaxLength to TextBoxFor or other controlls using data annotations
watch this example on YouTube
1. Metadata
[StringLength(3, ErrorMessage ="{0} cannot be longer than 3 chars")]
public string Name { get; set; }
2. Javascript
$(document).ready(function () {
$('input[data-val-length-max]').each(
function (index) {
$(this).attr('maxlength', $(this).attr('data-val-length-max'));
});
});
3. Layout
@Scripts.Render("~/Scripts/MaxLength.js")
1. Metadata
[StringLength(3, ErrorMessage ="{0} cannot be longer than 3 chars")]
public string Name { get; set; }
2. Javascript
$(document).ready(function () {
$('input[data-val-length-max]').each(
function (index) {
$(this).attr('maxlength', $(this).attr('data-val-length-max'));
});
});
3. Layout
@Scripts.Render("~/Scripts/MaxLength.js")
MVC - How to display proper name in Validation error message
Watch this example on YouTube
Replace
[Required(ErrorMessage ="this field is mandatory")]
public string Name { get; set; }
with
[Required(ErrorMessage ="{0} field is mandatory")]
public string Name { get; set; }
or even with
[Display(Name="Modified Name")]
[Required(ErrorMessage ="{0} field is mandatory")]
public string Name { get; set; }
Replace
[Required(ErrorMessage ="this field is mandatory")]
public string Name { get; set; }
with
[Required(ErrorMessage ="{0} field is mandatory")]
public string Name { get; set; }
or even with
[Display(Name="Modified Name")]
[Required(ErrorMessage ="{0} field is mandatory")]
public string Name { get; set; }
Wednesday, 1 November 2017
MVC - Display only 'header' message in @HTml.ValidationSummary
Watch this example on YouTube
to do so replace
@Html.ValidationSummary("Fix all errors")
with
@Html.ValidationSummary(true, "Fix all errors")
to do so replace
@Html.ValidationSummary("Fix all errors")
with
@Html.ValidationSummary(true, "Fix all errors")
MVC - Prevent @Html.ValidationSummary from displaying message on loading
Watch this fix on YouTube
to fix it add the following to css file
.validation-summary-valid{
display:none;
}
to fix it add the following to css file
.validation-summary-valid{
display:none;
}
MVC - How to modify @Html.ValidationSummary so it is not displaying header message
Watch this example on YouTube
To do so replace
@Html.ValidationSummary("Fix all the errors")
With
@Html.ValidationSummary("")
To do so replace
@Html.ValidationSummary("Fix all the errors")
With
@Html.ValidationSummary("")
Subscribe to:
Posts (Atom)