简体   繁体   English

ASP.NET MVC如果Excel文件中的数据为null或0,则不要将数据添加到表中

[英]ASP.NET MVC Don't add data to table if it is null or 0 from excel file

I have an excel file that has the ff. 我有一个带有ff的Excel文件。 data: 数据:

ordNo - ordDate ordNo - ordDate
9 - 2013-10-22 9-2013-10-22
10 - null 10-空
11 - 0 11-0
12 - 2013-10-23 12-2013-10-23
13 - 2013-10-24 13-2013-10-24

I also have this code below and it also add those who have NULL or 0 ordDate in the orderTable: 我在下面也有这段代码,它还会在orderTable中添加那些具有NULL或0 ordDate的代码:

using (var trans = DB.db.GetTransaction())
                                    {
                                        ordNo = Convert.ToInt32(DB.db.Insert("dbo.orderTable", "ordNo", new
                                                                                                                {
                                                                                                                    ordNo = data.ordNo,
                                                                                                                    ordDate = data.ordDate,
                                                                                                                }));

                                        trans.Complete();
                                    }

I want to add the ordNo and ordDate in the orderTable but only those who have dates. 我想在orderTable中添加ordNo和ordDate,但仅添加那些有日期的对象。

How can I do that by uploading an excel file and with the use of asp.net mvc? 如何通过上传Excel文件并使用asp.net mvc来做到这一点?

I badly need your help guys. 我非常需要您的帮助。 Thanks :) 谢谢 :)

using (var trans = DB.db.GetTransaction())
{
    if(data.ordDate!=null)
    {
        ordNo = Convert.ToInt32(DB.db.Insert("dbo.orderTable", "ordNo", new {ordNo =data.ordNo,ordDate = data.ordDate,}));
    }
    trans.Complete();
}

If you have string data type as ordDate , you can add additional condition to check 0 as well 如果您的字符串数据类型为ordDate ,则还可以添加其他条件以检查0

    if(!String.IsNullOrWhiteSpace(data.ordDate) 
                   && data.ordDate.Trim() !="0")
    {


    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM