Wednesday, August 6, 2014

Basic Html page with Angular js in 2mins

We only need one html file for this. We can also use three files for this purpose.

1. Angular.js file – this is the main javascript file we need to make page support for Angular js. We can include it in our folder or we can directly take it from CDN.

2. Basic Html file – this file should contain ng-app in any HTML tag. ng-controller,ng-repeat and {{variable}} are code syntaxes.

3. CardController.js file -  this file contains controller class and with $scope variable it defines its parameters.

<html ng-app xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<!--<script src="scripts/angular.min.js"></script>-->
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<script language="javascript">
//we can also use CardController.js for this
var CardController = function ($scope) {
$scope.cards
= [{ Id: 1 }, { Id: 4 }];
};
</script>
</head>
<body ng-controller="CardController">
<div ng-repeat="card in cards" class="CardItem">
Id: {{card.Id}}
</div>
</body>
</html>

Output will be
Id: 1
Id: 4


Hope you wanted to learn more simple beginners lessons on AngularJS covering most parts with examples. W3Cschools.com - http://www.w3schools.com/angular/default.asp

Tuesday, August 5, 2014

Remove Carriage Return, Line Feed, Tab in TSQL

Following code shows way to remove all spaces from selected column values. We generally use RTRIM and LTRIM build in string functions but sometimes it doesn’t remove some spaces due to string contains carriage return life feed and tab like control characters. We can’t see these characters with grid result view but we can see in text result view in MSS Management Studio.

REPLACE(REPLACE(REPLACE(RTRIM(LTRIM(ColumnName)), CHAR(10), ''),CHAR(13), ''),CHAR(9), '')
CHAR(9) - 'Tab'
CHAR(10) - 'Line Feed'
CHAR(13) - 'Carriage Return'

Wednesday, June 4, 2014

Started to deep learn Software Design

image

Clean Code: A Handbook of Agile Software Craftsmanship [Robert C. Martin]

Tuesday, April 1, 2014

Create a user for SQL Server authentication

First log into sql server using sql management studio or other relevant tool as an administrator.
Then use following command to create testuser in testdb database. You can ignore DEFAULT_DATABASE part as well if it is not working.

-- Create user for SQL Authentication
USE master
CREATE LOGIN testuser
    WITH PASSWORD = 'test#123',DEFAULT_DATABASE = testdb
GO

-- Creates a database user for the login created above.
USE testdb
CREATE USER testuser FOR LOGIN testuser
GO

Saturday, December 15, 2012

System.BadImageFormatException

I got following error when running Test project with visual studio 2010.

SetUp : System.BadImageFormatException : Could not load file or assembly 'TP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Solution:

When I checked there were difference in Solution platforms of two project.One set to x86 while other project set to AnyCPU.So I changed it from AnyCPU to x86.It works.

Wednesday, July 18, 2012

C# Password encrypting and decrypting

public static string HashPassword(string password)
{
    var provider = new SHA1CryptoServiceProvider();
    var encoding = new UnicodeEncoding();
    var hash= provider.ComputeHash(encoding.GetBytes(password));
    return Convert.ToBase64String(hash);
}

var pwdstr=HashPassword(password);
var user=(from u in context.Users
          where u.UserName.Equals(username) && u.pwd.Equals(pwdstr)  
          select u);

This is simple way to set and check password stored in database.Hope it will helpful.To store in a database use first method and to compare use second method.Until next post cheers!!!

Tuesday, April 10, 2012

MSSQL useful tips

MSSQL set null when value is not numeric in select query

SELECT CASE ISNUMERIC(column1) WHEN 1 THEN column1 ELSE NULL END FROM table1

SQL Server Error Messages - Msg 8152 - String or binary data would be truncated.  The statement has been terminated.

This error message is occurred when I tried to insert data to values from another table.It’s due to one column in the table that im inserting data have lesser length than other table column.(varchar(25) – varchar(max)).It couldn’t found previously because second table column I have used max length but when inserting data it filled with strings that contains more than 25 characters.

I found another command to skip that error and continue but its like a try catch statement without catch part(thanks yasindu bro for nice example).

SET ANSI_WARNINGS OFF

Need to use above command before inserting records.but sometimes it’s not working

Inserting multiple records to a table

This isn’t simple thing but I previously work with MySQL and that is different and we can’t use

INSERT INTO tblName (column1,column2)
VALUES
('Value1','value11'),
('Value2','value22'),
('Value3','value33')
INSERT INTO tblName (column1,column2)
select ‘Value1′,’Value11’
UNION ALL
select ‘Value2′,’Value22’
UNION ALL
select ‘Value3′,’Value33’