Solved

Default Value For A Blank Field

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

733 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