Hi...

I have one problem regarding how to check whether the record already have or not then do insert or update...I'm using firebird database....i want to pull all record from one table to other database . Here my coding but i'm get stuck to do insert or update...hope anyone can help me...tq

Dim fbcmd As New FbCommand
        Dim fbcmd1 As New FbCommand
        Dim cmd As New FbCommand
        fbcmd = New FbCommand("select  * from CARDHOLDER  ", IBSS)


IBSSNEW = New FbConnection("User=xxxx;" + "Password=XXXX;" + "Database=C:\ibss\database\ibss.gdb;" + "DataSource=a;" + "Port=3050;" + "Dialect=3;" + "Charset=NONE;" + "Role=;" + "Connection lifetime=15;" + "Pooling=true;" + "MinPoolSize=0;" + "MaxPoolSize=50;" + "Packet Size=8192;" + "ServerType=0")

        IBSSOLD = New FbConnection("User=xxx;" + "Password=xxx;" + "Database=D:\ibss\database\ibss.gdb;" + "DataSource=b;" + "Port=3050;" + "Dialect=3;" + "Charset=NONE;" + "Role=;" + "Connection lifetime=15;" + "Pooling=true;" + "MinPoolSize=0;" + "MaxPoolSize=50;" + "Packet Size=8192;" + "ServerType=0")


IBSSUMP.Open()
        IBSSDR = fbcmd.ExecuteReader()
        Dim bFlag As Boolean = True
        Do Until Not bFlag
            While (IBSSDR.Read())

                cmd = New FbCommand("SELECT * FROM CARDHOLDER WHERE  CARDHOLDERID = '" & IBSSDR.Item(0).ToString & "' ", IBSSNEW)

                Dim IBSSDR1 As FbDataReader
                IBSSNEW.Open()
                IBSSDR1 = cmd.ExecuteReader
                                   Dim intVal As Integer
                 intVal = IBSSDR1.HasRows


                While IBSSDR1.Read
                    If intVal > 0 Then

                        Console.ForegroundColor = ConsoleColor.Magenta
                        Console.WriteLine(vbTab & IBSSDR1.Item("CARDHOLDERID") & vbTab & IBSSDR1.Item("NAME"))
                        IBSSDR1.NextResult()


                    End If

                    If Not IBSSDR1.HasRows Then
                        Console.ForegroundColor = ConsoleColor.Green
                        Console.WriteLine(vbTab & IBSSDR.Item("CARDHOLDERID") & vbTab & IBSSDR.Item("NAME"))
                        IBSSDR1.NextResult()
                    End If


                End While


                IBSSNEW.Close()




            End While
            bFlag = IBSSDR.NextResult()
        Loop

I can't see where you are checking for it. Or you don't know how to go about it?

Can you break it down in pseudo code what you are trying to do?

If I Understand properly you want to Check if something is missing and make it if it's not there.

Well Can you tell me what you are checking for and what you want to replace it with?

You may want to look at CASE WHEN.

Example

SELECT CASE WHEN Name IS NULL THEN '-1' ELSE Name END FROM Customers WHERE CustomerID = 12345

then you can check if -1 is returned then the record doesn't exist and you can do what you want with it.

From what I understand CASE works in Firebird DB

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.