Monday, February 16, 2015

How to find the Second value (could be largest or lowest) from a table.?


I have One table with StatusIDHeld in "UserStatusHistory"Table with this column userid,StatusIDHeld and statusChangedOn. One customer could be multiple StatusIDHeld . I am finding out just previous one StatusIDHeld that mean the second StatusIDHeld which just before he had hold.

To be able to get 1., 2. or n-th record depending on sort order, use ROW_NUMBER() function.
                        SELECT StatusIDHeld 
   FROM
   (
    SELECT StatusIDHeld, ROW_NUMBER () OVER(order by statusChangedOn DESC) as RowNo
    FROM UserStatusHistory where userid= 1037146 
   ) AS t
   where t.RowNo = 2


Happy Query .....

SQL SERVER – Simple Example of Cursor with update table

A cursor is a set of rows together with a pointer that identifies a current row.

DECLARE cursor_activatedOnEmpty CURSOR FOR SELECT userid, statusid,RegisteredOn, activatedOn, RealActivationDate FROM UserProfile where statusID=1330 and  activatedOn is null; 
DECLARE @userid INT;
DECLARE @statusid INT;
DECLARE @RegisteredOn Date;
DECLARE @activatedOn Date;
DECLARE @RealActivationDate Date;
DECLARE @PreviousStatusID INT;
OPEN cursor_activatedOnEmpty;
FETCH NEXT FROM cursor_activatedOnEmpty INTO @userid, @statusid,@RegisteredOn, @activatedOn,@RealActivationDate;
WHILE @@FETCH_STATUS = 0  
BEGIN    
 
 SET @PreviousStatusID = (select top 2 StatusIDHeld from dbo.UserStatusHistory where userid=@userid order by statusChangedOn DESC)  
       if (@PreviousStatusID=1325)
       update UserProfile set activatedOn=@RegisteredOn where userid=@userid

       FETCH NEXT FROM cursor_activatedOnEmpty INTO @userid, @statusid,@RegisteredOn, @activatedOn,@RealActivationDate;
END;
CLOSE cursor_activatedOnEmpty;
DEALLOCATE cursor_activatedOnEmpty;

Happy Cursor!!

Sunday, February 8, 2015

Complex Json deserialization C# (class is not supported for deserialization of an array)


I am trying to deserialization array bellow this way.
This is my json file.
[
   [
      {
         "name":"Riaz Kabir",
         "url":"https://recruit.theladders.com/resumeviewer?jobseekerId=01-sid-BDLBKUPMIL6HGZ22MOAJJIWYGE",
         "summary":"ASP.NET MVC Developer Hewlett-Packard (HP) (1/2013-Present) Location: Schenectady, NY Compensation: $50k+ Previous Titles/Companies: 2016 ►",
         "role":"ASP.NET MVC Developer at Hewlett-Packard (HP)",
         "compensation":"$50k+",
         "education":"BS, Computer Science and Engineering, Asian University of Bangladesh",
         "expertise":"Databases , IT Consulting , Software Development , Front End Development",
         "years":"Less than 5",
         "relocation":"Schenectady, NY Within 1000 miles of 12305 Would need to relocate here",
         "resume":"0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAP",
         "resumeExtension":"doc",
         "resumeMimeType":"application/msword"
      }
   ]
]

Bellow my candidate Resume class
public class CandidateResume
        {

            public string name { get; set; }
            public string url { get; set; }
            public string summary { get; set; }
            public string role { get; set; }
            public string compensation { get; set; }
            public string education { get; set; }
            public string expertise { get; set; }
            public string years { get; set; }
            public string relocation { get; set; }
            public string resume { get; set; }
            public string resumeExtension { get; set; }
            public string resumeMimeType { get; set; }

        }

I have bind this "WebScrappingCandidate" class this bellow way.
                JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
                List> myobj = jsSerializer.Deserialize>>(description);

                foreach (List listCandidateResume in myobj)
                {
                    foreach (CandidateResume candidateResume in listCandidateResume)
                    {
                        WebScrappingCandidate webScrappingCandidate = new WebScrappingCandidate();
                        webScrappingCandidate.FullName = candidateResume.name;
                        webScrappingCandidate.ResumeUrl = candidateResume.url;
                        webScrappingCandidate.Summary = candidateResume.summary;
                        webScrappingCandidate.PositionName = candidateResume.role;
                        webScrappingCandidate.Compensation = candidateResume.compensation;
                        webScrappingCandidate.Education = candidateResume.education;
                        webScrappingCandidate.Skills = candidateResume.expertise;
                        webScrappingCandidate.YearsOfExperience = candidateResume.years;
                        webScrappingCandidate.Relocation = candidateResume.relocation;                        
                        webScrappingCandidate.ResumeText = candidateResume.resume;                                                                  
                    }                                       
                }   

Happy Programming :)

Monday, March 24, 2014

Files has invalid value "<<<<<<< .mine". Illegal characters in path [Solved]

First you have to remove any characters like "<<<<<<< .mine" or similar from the file that you will see in your project Folder.

If you don't find "<<<<<<< .mine" this one then you have to search in bollow this file
.csproj.FileListAbsolute.txt

which contains a list of all the paths and recompile ...it worked for me :)

Wednesday, December 11, 2013

Keep password textbox value during postback asp.net


In this article, I will explain how to keep password & Retype password textbox value during postback in asp.net
 protected void Page_Load(object sender, EventArgs e)
    {
       if (!(String.IsNullOrEmpty(txtPassword.Text.Trim())))
        {
            txtPassword.Attributes["value"] = txtPassword.Text;
        }
        if (!(String.IsNullOrEmpty(txtRePassword.Text.Trim())))
        {
            txtRePassword.Attributes["value"] = txtRePassword.Text;
        }
   }



Hope freshers will find it helpful :)

Thursday, November 14, 2013

C# multiple value return from single function

There are a number of ways to return two object from one function. You can class or structure and another one as out parameter. Alternatively, you can use generic type with two members. Such type, in particular, it Tuple:

#I am using Tuple to returns 2 datetime value(fromDate , toDate )
  public Tuple GetDates()
   {

          DateTime fromDate = DateTime.Now;
          DateTime toDate = DateTime.Now;
          int year = Convert.ToInt32(this.ddlQYear.SelectedItem.Value);

            if (Convert.ToInt32(ddlQ.SelectedItem.Value) > 0)
            {
                int month = Convert.ToInt32(ddlQ.SelectedItem.Value);
                fromDate = new DateTime(year, month, 1);
                if (month == 12)
                    toDate = new DateTime(year + 1, 1, 1);
                else
                    toDate = new DateTime(year, month + 1, 1);
            }
            return new Tuple(fromDate, toDate);
   }
===========Call this function bellow way==============================
            
DateTime fromDate = GetDates().Item1;
DateTime toDate = GetDates().Item2;


#Another way use "out" keyword:

 public static int GetDates(out DateTime FDate, out DateTime TDate)
   {
            DateTime fromDate = DateTime.Now;
            DateTime toDate = DateTime.Now;

           // Calculate your date

            FDate=fromDate ;
            TDate=toDate
     

         return 1;
   }
Hope that this helps!!

Wednesday, November 13, 2013

Swap column values in sql server 2008

Suppose we have a table named USER with 3 columns: USERID, USERName, USERAddress.

              USERID: int 
USERName: varchar(100)
USERAddress: varchar(100)


Swap with the temporary variable:
-----------------------------------------------


DECLARE @temp AS varchar(10)
 
UPDATE USER SET @temp=USERAddress, USERAddress=USERName, USERName=@temp
 


Hope freshers will find it helpful :)

Thursday, November 7, 2013

C# “is inaccessible due to its protection level” [Solved]

Some time its happen when your modifier are private or protected but need to access anywhere that time just your function need to be protected to public.

I had happened same problem when i write code radio button "OnCheckedChanged" event. I have solved that way to change modifier protected to public.


 public void ShareTransferSelection(object sender, EventArgs e)
    {
      // Code here
    }


Happy Programming!!

Monday, October 21, 2013

RSS Feed Reader with jQuery

I am using the jQuery & FeedEk plugin to parse rss feed.

Step 1 – Include jQuery and FeedEk.js

 

Step 2 – Specify a DIV where you need the feed displayed

3- Add the Javascript that will populate the placeholder


Well there you have it; a slick, easy to use FeedEk RSS Reader!!

Friday, October 18, 2013

[Solved]How to delete an uploaded image in asp.net ?

Uploaded image you can easily delete by server side code.

try {
FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + FileName);
if (TheFile.Exists) {
File.Delete(MapPath(".") + "\\" + FileName);
}
else {
throw new FileNotFoundException();
} 
} 

Good Day!!!