Solved

Default Value For A Blank Field

Posted on 2013-05-21
5
533 Views
Last Modified: 2013-05-21
Hi Experts!

Thanks for reading this.

So, using LinqToExcel to pull data into a Model:

string sFileName = @"C:\Working Directory\Product.xlsx";

var excel = new ExcelQueryFactory(sFileName);
excel.DatabaseEngine = LinqToExcel.Domain.DatabaseEngine.Jet;

var per = from x in excel.Worksheet<Model1>("Product")
            select x;

Open in new window

    public class Model1
    {
        public string PRODUCT { get; set; }
        public string STARTDATE { get; set; }
        public string ENDDATE { get; set; }
    }

Open in new window

In per (Model1) how would you update the blank value in the End Date to a default value say 20781231?

The content of Product looks like this (with Blank End Date):
Product Listing
TIA!
Product.xlsx
0
Comment
Question by:allanau20
  • 4
5 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39185783
Hi allanau20;

All that would be needed is to modify your Model1 class as follows.

public class Model1
{
    public string PRODUCT { get; set; }
    public string STARTDATE { get; set; }
    private string _Enddate; 
    public string ENDDATE
    {
        get { return _Enddate; }
        set
        {
            if(String.IsNullOrEmpty(value))
                _Enddate = "20781231";
            else
                _Enddate = value;
        }
    }
}

Open in new window


.
0
 
LVL 5

Author Comment

by:allanau20
ID: 39185838
Thanks; I'll try it now.
0
 
LVL 5

Author Comment

by:allanau20
ID: 39185883
Hi FernandoSoto,

When I look at the per (Model1) we can see that if the End Date is blank it will default to 20781231. So, it satisfied the requirement.

However, this question is a an extension of the previous question,  in prods (Model1) for Product = 0002-0800 the End Date = 20340201 was selected. It should have been 20781231.
For the other Product (0002-1407, 0002-1975, 0002-3004, 0002-3227) it selected the correct End Date (latest end date for that product).

I'll open up another question.

Thanks again for your help!
0
 
LVL 5

Author Closing Comment

by:allanau20
ID: 39185884
awesome!
0
 
LVL 5

Author Comment

by:allanau20
ID: 39185932
Hi FernandoSoto,

I think we're almost there with selecting the earliest and latest date with Model1.
If you've the time again please kindly take a look at this question:

Thanks again for your help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now