?
Solved

Default Value For A Blank Field

Posted on 2013-05-21
5
Medium Priority
?
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

801 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