此操作的逻辑 [英] Logic for this operation

查看:63
本文介绍了此操作的逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一张表说Tab1(col1,col2)

条目(对应条目)

Col1 col2

a - sep1

b - sep2

c - sep3

d - sep4

e - sep5



现在如果我上传新条目如

Col1 col2

a - sep3

b - sep2



所以如果这个新条目没有退出,那么它只是插入这些新条目,否则更新它。

我想要它的C#逻辑,

我试过这个,但它没有工作

I have a table in my database say Tab1(col1, col2)
entries are(corresponding entries)
Col1 col2
a - sep1
b - sep2
c - sep3
d - sep4
e - sep5

now if i upload new entries like
Col1 col2
a - sep3
b - sep2

so if this new entries does not exits then it simply INSERT these new entries else update it.
I want C# logic for it,
I tried this but its not working

if (isSuccess)
{
    if (!(isWellIdExists(impexp.WellId) || isUploadedDateExists(impexp.UploadedDate)))         
    {
        int result = ExecuteQuery("InsertImpExpData", 
            SerialIDParameter, 
            WellIdParameter, 
            DateRecievedParameter, 
            DueDateParameter, 
            UploadedFootageParameter, 
            UploadedDateParameter, 
            PriorityParameter, 
            RemarkParameter);
    }
}
else
{
    int result = ExecuteQuery("UpdateImpExp");
}
return isSuccess;





删除了SHOUTING,添加了代码块 - OriginalGriff [/ edit]



[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]

推荐答案

首先,你应该使用单一检查...

使用您提供的代码,您将获得



适用于isWellIdExists和

适用于isUploadedDateExists

对于9月3日你的例子



因为或OR条件然后否定它会让你失误=>更新时应该插入



z Sep3将为您提供一个真实的(isUploadedDateExists)并且您将再次获得更新



类似的逻辑适用于所有其他组合,如果id和日期从未进入yorr系统,你只会得到插入



正确实施应该是



First of all, you should use single check for both...
With the code you provided you will have

True for isWellIdExists and
True for isUploadedDateExists
for a Sep3 as per your example

because or OR condition and then negating it will get you false => Update when you should get Insert

z Sep3 will get you one true (isUploadedDateExists) and you will get update again

Similar logic goes for all other combinations, you'll only get insert if id AND date never entered into yorr system

Correct implementation should be

if (ExistsWellID_And_UpdateDate(id, date)) {
    // update
}
else
{
    // insert
}





这当然取决于你的功能正在做他们的名字所暗示的......



This is of course conditional on your function doing what their names imply...


if (isWellIdExists(impexp.WellId) && isUploadedDateExists(impexp.UploadedDate))
{
int result = ExecuteQuery("UpdateImpExp");
}
else
{
int result = ExecuteQuery("InsertImpExpData", 
SerialIDParameter, 
WellIdParameter, 
DateRecievedParameter, 
DueDateParameter, 
UploadedFootageParameter, 
UploadedDateParameter, 
PriorityParameter, 
RemarkParameter);
}


这篇关于此操作的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆