8
Answers

Replace nulls in column with Auto Increment by number

Photo of Rajeevkumar

Rajeevkumar

7y
281
1
Hi,
 
I have one table with two columns. S.No and Date. S.No has null values. 
S.No Date(DD-MM-YYYY)
Null 19-10-1993
Null 12-03-1995
Null 15-02-2017
Null 26-08-2010
Null 01-06-2016
 
 I need to replace these nulls with number in the sequence based on date.
 
Can you please help on this?
 
Thanks in advance!!! 

Answers (8)

2
Photo of Mukesh Nayak
NA 1.5k 317.4k 7y
Hi Laxman ,
 
Now there is 2 extension for the select . Please refer the image below : 
 
First extension in the image above is having one parameter  which is just element itself to be manipulated.
Now in the second case it is accepting  2 parameter where the first parameter is the element itself and second parameter is the index.
 
Now in you code using second parameter you are iterating through the all the value using substring. For example if your deqn.value = "\\tag SIGMA INSTITUTE" so it will iterate and get all the value such as 
\\tagSIGMA INSTITUTE    (i = 0)
tagSIGMA INSTITUTE (i=1)
agSigMA INSTITUTE (i = 3)
..
..
E (i = n)
 
then from all this element its checking where there \\tag  
 and getting count. 
 
 
Regards,
Mukesh Nayak 
1
Photo of Laxmidhar Sahoo
NA 2.3k 1.4k 7y
hi mukesh
The first is the iterated charecter
second is the position(index) of the iterated charecter 
 
1
Photo of Laxmidhar Sahoo
NA 2.3k 1.4k 7y
sir I made some changes with your code and bellow given a example .sir I look it and get back to me
  1. public ActionResult testdoublelambdacount()  
  2.       {
  3.           string strxml = "" +  
  4.                           "" +  
  5.                               " \\tag SIGMA INSTITUTE" +  
  6.                                "650" +  
  7.                          "" +  
  8.                          "" +  
  9.                               "ORCHID INSTITUTE" +  
  10.                                "1200" +  
  11.                           "" +  
  12.                           "";  
  13.           XmlDocument xDoc = new XmlDocument();  
  14.           xDoc.LoadXml(strxml);  
  15.           XmlNodeList xmlNodeList = xDoc.SelectNodes("/info/collage"); 
  16.           foreach (XmlNode xmlNode in xmlNodeList)  
  17.           {
  18.               string nodevalue = xmlNode["name"].InnerText;
  19.               var matchCount = nodevalue.Select((c, i) => nodevalue.Substring(i)).Count(sub => sub.StartsWith("\\tag")); 
  20.           }
  21.           return View();  
  22.       }  
 
0
Photo of Mukesh Nayak
NA 1.5k 317.4k 7y
Hi Laxman 
 
I modified the code something like  
  1. var matchCount = deqn.Select((c, i) => deqn.Substring(i) + " Iteration : " + i + " Element : " + c ).ToList();
and putting the break point  you will get the following : 
 
 So i = 0,  deqn.Substring(i)  = "\\tagSIGMA INSTITUTE", c ="",
      i = 1, deqn.Substring(i) = "\\tagSIGMA INSTITUTE", c ="\\",
      i = 2 , deqn.Substring(i) = "tagSIGMA INSTITUTE", c ="t",
                                       .........
                                       .........
 
Mukesh Nayak 
0
Photo of Ab Laxman
NA 9 281 7y
Hi Mukesh,
 Are the below strings values of "c" in the lambda?
  1. \\tagSIGMA INSTITUTE (i = 0)  
  2. tagSIGMA INSTITUTE (i=1)  
  3. agSigMA INSTITUTE (i = 3) 
or are they the value of "i"?
Sorry if this question sounds stupid but I'm a newby:)