简体   繁体   中英

VB.Net Merge/Update query not working

I have two sql database tables klaar and klaarvb, which I would like to merge with the following code :

      Dim READER As SqlDataReader

    Try
        konneksie.Open()
        Dim query As String

        query = "MERGE blokkeklaar as target" & _
                "USING blokkeklaarVB AS source" & _
                "On target.Plaasblok = source.Plaasblok" & _
                "WHEN MATCHED THEN" & _
                "UPDATE SET klaarvb = source.klaarvb;"

        COMMAND = New SqlCommand(query, konneksie)
        READER = COMMAND.ExecuteReader
        MessageBox.Show("Inligting vanaf blokkeklaarVB  na blokkeklaar")

        konneksie.Close()



    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
    End Try

I get an error " Incorrect syntax near blokkeklaarVB"

When I run the statement in SQl Manager I get the correct result :

 MERGE blokkeklaar as target
                USING blokkeklaarVB AS source
                On target.Plaasblok = source.Plaasblok
                WHEN MATCHED THEN
                UPDATE SET klaarvb = source.klaarvb;

I cannot figure out what I am missing.

Regards

You're missing spaces between words before the line continuation when concatenating different lines.

    query = "MERGE blokkeklaar as target " & _
            "USING blokkeklaarVB AS source " & _
            "On target.Plaasblok = source.Plaasblok " & _
            "WHEN MATCHED THEN " & _
            "UPDATE SET klaarvb = source.klaarvb;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM