Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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;


[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]
Posted
Updated 9-Sep-14 3:56am
v6
Comments
OriginalGriff 9-Sep-14 9:33am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
Abhishek Jaiswall 9-Sep-14 12:00pm    
Okay, got it, thanks!
now can you please give some relevant answer ?
OriginalGriff 9-Sep-14 12:07pm    
I probably could, yes.
But...you started off by shouting at me, so I am not inclined to read the actual question.
Maybe if it's still there in a couple of days, I'll have a look.
Tejas Vaishnav 9-Sep-14 9:39am    
What code you have write in isWellIdExists and isUploadedDateExists functions. can you update your question and add that function code too.
Abhishek Jaiswall 9-Sep-14 12:01pm    
whatever i had written is enough for that question, I just need logic for my question.. Please suggest some.

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

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


This is of course conditional on your function doing what their names imply...
 
Share this answer
 
v3
Comments
George Jonsson 9-Sep-14 10:26am    
Logic table
IdExist DateExist Result
false false !{false OR false) = true -> Insert
false true !(false OR true) = false -> Update
true false !(true OR false) = false -> Update
true true !(true OR true) = false -> Update

Then it depends if this is the desired logic.
Abhishek Jaiswall 9-Sep-14 11:58am    
you mean to say i need to write it as
if (isWellIdExists(impexp.WellId) && isUploadedDateExists(impexp.UploadedDate))
{
int result = ExecuteQuery("UpdateImpExp");
}
else
{
int result = ExecuteQuery("InsertImpExpData",
SerialIDParameter,
WellIdParameter,
DateRecievedParameter,
DueDateParameter,
UploadedFootageParameter,
UploadedDateParameter,
PriorityParameter,
RemarkParameter);
}
Sinisa Hajnal 10-Sep-14 2:13am    
No, I mean that if the isWellIdExists just looks at the ID, without looking at the date IN THE SAME QUERY you will get true if ID exists anywhere in the table with any date.

Per your example, I understood that "a Sep3" combination does should be inserted as it doesn't exist (there "a Sep1" and "c Sep3", but no "a Sep3". Maybe I misunderstood and "a Sep3" should update a? Or Sep3? Which has priority? That's why I think you meant both.


Hmmm...somehow still doesn't sound clear: Let's try it this way:
Do your functions check the same row? Or just the existence of a record anywhere in the table?
C#
if (isWellIdExists(impexp.WellId) && isUploadedDateExists(impexp.UploadedDate))
{
int result = ExecuteQuery("UpdateImpExp");
}
else
{
int result = ExecuteQuery("InsertImpExpData", 
SerialIDParameter, 
WellIdParameter, 
DateRecievedParameter, 
DueDateParameter, 
UploadedFootageParameter, 
UploadedDateParameter, 
PriorityParameter, 
RemarkParameter);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900