Solved

Default Value For A Blank Field

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

691 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