1

I have records from server that I want to copy, so I used datareader to select all, during selection the insert also process. This is the pseudo code:

while datareader.read
        For f As Integer = 0 To datareader.FieldCount - 1
                Values = Values & datareader.GetValue(f)
        Next
    Dim ss as string ="Insert into xtable(a,b,c,d,e,f) select " & values & " where not Exist (select * from xtable)" ''//is this right?
    Dim sc as new sqliteCommand(ss,mycon)
    sc.ExecuteNonQuery
    End While
    sc.dispose

What is the exact sql statement to insert only if record doesn't exist in my current table?

I used some of this code, but a filter was defined: like x What if I just want to insert records that doesn't exist in the table I want.

Dim ss As String = "insert into xtable(x,y,z) select $x, $y,$z 
where not exists (select 1 from xtable where x=$x)"
0

1 Answer 1

1

Try this:

if not exists(select 1 from xtable)
   begin
       insert into xtable(x,y,z) select $x, $y,$z from xtable
   end

I don't think the above will work, but this link should give you the answer you're looking for.

Sign up to request clarification or add additional context in comments.

2 Comments

yes, I believe it is. I haven't used sqlite in a long time though.
I think the answer is in my sample code I wrote, but thanks for the push. And the link sample declared a filter. Still Listening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.