【问题标题】:insert if not exists in sqlite with vb.net如果在带有 vb.net 的 sqlite 中不存在,则插入
【发布时间】:2012-05-25 17:55:21
【问题描述】:

我有来自服务器的记录要复制,所以我使用数据读取器全选,在选择期间插入也处理。 这是伪代码:

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

仅当当前表中不存在记录时才插入的确切 sql 语句是什么?

我使用了其中的一些代码,但定义了一个过滤器:like x 如果我只想插入我想要的表中不存在的记录怎么办。

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

【问题讨论】:

    标签: sql vb.net select insert


    【解决方案1】:

    试试这个:

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

    我认为上面的方法行不通,但是this link should give you the answer you're looking for.

    【讨论】:

    • 是的,我相信是的。不过我很久没用过sqlite了。
    • 我认为答案在我编写的示例代码中,但感谢您的推动。并且链接示例声明了一个过滤器。还在听。
    猜你喜欢
    • 2021-10-14
    • 2015-03-31
    • 2011-01-13
    • 1970-01-01
    • 2013-10-20
    • 2013-07-23
    • 1970-01-01
    • 2018-09-17
    相关资源
    最近更新 更多