Skip to main content

Posts

Showing posts from July, 2016

Password only alphanumeric no special character -MVC C#

Password matching expression. Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit. Expression:   ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$ public class LoginViewModel { [ Required (ErrorMessage= "Required" )]       [ Display (Name = "User name" )] public string UserName { get ; set ; } [ Required (ErrorMessage = "Required" )] [ DataType ( DataType .Password)] [ RegularExpression ( "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$" , ErrorMessage = "Password Alphanumeric Only. Minimum length 8" )] [ Display (Name = "Password" )] public string Password { get ; set ; } }

Remove the last character in a string in -C#

You can remove last character or no of last character with below code. please try this.   static void Main( string [] arg)         {                  string temp = "My Name is Mohammad Maksudur Rahman.>" ;        var stringValue = temp.Remove(temp.Length-1);                   Console .WriteLine( "Your string value: {0}" , stringValue);                 Console .ReadLine();           stringValue = temp.Remove(temp.Length-2);           Console .WriteLine( "Your string value: {0}" , stringValue);                 Console .ReadLine();          } You can do this in SQL server.  Remove the last character in a string in -SQL Server

Get Previous Month's First and Last Date -C#

Here this code, your can get previous month's first and last day. It's simple   static void Main( string [] arg) {    var year = DateTime .Today.Year;    var month = DateTime .Today.Month;    var firstDate = new DateTime (year, month, 1).AddMonths(-1);    var lastDate = new DateTime (year, month, 1).AddDays(-1);    Console .WriteLine( "First day Previous Month: {0}" , firstDate);    Console .WriteLine( "Last day Previous Month: {0}" , lastDate);    var  lastday =  GetMonthLastDate ( 2015 , 6 );   Console .WriteLine( "Last day : {0}" , lastDate);    Console .ReadLine(); } You can use below method to get last date of any month of the any year. private DateTime GetMonthLastDate( int year, int month) {     return new DateTime (year, month, DateTime .DaysInMonth(year, month)); }

Remove the last character in a string in -SQL Server

Remove last character  or no of character remove in SQL server. Its so easy in sqlserver built in function with SUBSTRING , sometimes its little bit tricky for developer when he/she forget about SUBSTRING method. SUBSTRING ( expression ,start , length ) Original String is  'My Name Is Maksud,' SELECT SUBSTRING('My Name Is Maksud,', 1, LEN('My Name Is Maksud,') - 1) AS ResultString You can do this in C#, here you go  Remove the last character in a string in -C#

ROW_NUMBER -Sqlserver

This is a special keyword used for generate "Sequential No'   on a row within result set. Sequential no start from 1 for first row, second row no is 2 in each partition. Usually used in Select Statement. ROW_NUMBER () OVER ( [ <partition_by_clause> ] <order_by_clause> )  Arguments: ROW_NUMBER has Two Arguments are  1. Partition_by_clause and 2.   order_by_clause  ROW_NUMBER() with PARTITION : Partition BY Clause to generate Sequence No to separate of query result and Order By works on over clause for order the results. SELECT  ROW_NUMBER() OVER(PARTITION BY IsApproved ORDER BY Id DESC ) AS SL_NO ,[Name]       ,[Address]       ,[Telephone]  ,[IsApproved]       FROM [RemitERP].[dbo].[Agm_Agent]  WHERE IsApproved IS NOT NULL ROW_NUMBER()   Only  ORDER BY : Order by clause works all result of the query and generate sequence No.  SELECT         ROW_NUMBER() OVER( ORDER BY Id DESC ) AS SL_NO ,[Name]       ,[Address]       ,[Teleph

DBCC command to RESEED Table Identity Value – Reset Table Identity

Generally,  we are using identity column into table where identity value incrementally inserted.  DBCC command RESEED is used to reseed (reset) column identity. For example, your table has 20 rows that means last identity value is 20. if you want to reseed identity value will be 30, you can run following TSQL. DBCC  CHECKIDENT  ( yourtable ,  reseed ,  29 ); i f You reseed identity value which is below in current table, it will violate   the uniqueness constraint as soon as the values start to duplicate and will generate error. If you delete last row in current table and insert new row into current table, your new inserted identity value will be last (deleted identity value + incremental value). For example, you delete last three rows where Identity value is 20 - 22 ,so if you now insert new row,  identity value will be 23. That means seed value keep into transaction log.