user3056503
user3056503

Reputation: 7

ASP.NET MVC Get value from two column to one column

I have two columns from excel file:

delivery_date1 - delivery_date2

2013-10-14 - null

null - 2013-10-19

I want to update deliveries table using the two columns from the uploaded excel file but in the my table, I only have one column which is the delivery_date.

What I would like to have is like this (based on the excel data above):

delivery_date

2013-10-14

2013-10-19

How can I do that using asp.net mvc?

Here's my code:

delivery_id = Convert.ToInt32(DB.db.Insert("dbo.deliveries", "delivery_id", new                                                                                                                    {
    delivery_date = delivery_date1,
    delivery_date = delivery_date2,
}));

I got an error like this:

An anonymous type cannot have multiple properties with the same name.

Upvotes: 0

Views: 881

Answers (1)

musefan
musefan

Reputation: 48425

Which part of that error do you not understand? You cannot use the same property name twice!

I think this is what you want...

new 
{
    delivery_date = delivery_date1 == null ? delivery_date2 : delivery_date1
}

This will create a single property called delivery_date and will assign it the value of delivery_date1, or if delivery_date1 is null then it will be assigned with the value of delivery_date2

Upvotes: 3

Related Questions