Thursday, October 20, 2011

C# string split & LINQ operation

Spliting string in C# is one of the most interesting part. you can also perform your business logic operation on spliting part.
Hare is a list of serial no comes from database, i split the Serial no then just increment id no +1 on maximum serial no, and return to UI.
i also check hare is the serial no is in current year.



 internal string GetNewSerialNo()  
     {  
       string refence = "";  
       DateTime dt = DateTime.Now;  
       List<RFQ> _listAllRef =new List<RFQ>();  
       foreach (var objrfq in rfqDalObj.GetNewSerialNo())  
       {  
         string[] splitedRef = (objrfq.SerialNO).Split('-');  
         if(DateTime.Now.Year.ToString()==splitedRef[1])  
         {  
           _listAllRef.Add(objrfq);  
         }  
       }  
       List<int> rfqSerials = new List<int>();  
       if (_listAllRef.Count > 0)  
       {  
         foreach (var obj in _listAllRef)  
         {  
           string[] splitedRef = (obj.SerialNO).Split('-');  
           string[] splitedMainId = splitedRef[0].Split('Q');  
           rfqSerials.Add(Convert.ToInt32(splitedMainId[1]));  
         }  
         refence = "RFQ"+ (rfqSerials.Max() + 1) + "-" + dt.Year;  
       }  
       else  
       {  
         refence = "RFQ10001" + "-" + dt.Year;  
       }  
       return refence;  
     }  

Enjoy...

SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...