Solved

Default Value For A Blank Field

Posted on 2013-05-21
5
529 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 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

18 Experts available now in Live!

Get 1:1 Help Now