简体   繁体   中英

SQL (INSERT INTO) COMMAND DOES NOT WORK IN OLEDB IN VB.NET

I want to update in the "CIU" column in the database "GSDTS" and retrieve the data or values from the database "IFGTS" in the column "PRSOBNET" based on the conditions of the "ITM" column and the "GDN" column or warehouse. Do I have to do sql update or insert to please recommend the solution because I sql command in the code does not work at all and how can the sql command solution work? thanks jack

Sub InsertIntoGsdts()
        Try
            Dim sql As String = "INSERT INTO GSDTS (CIU) SELECT t1.PRSOBNET FROM IFGTS t1 WHERE NOT EXISTS(SELECT ITM FROM GSDTS t2 WHERE t2.ITM = t1.ITM) AND GDN = 'A.04.01.002.001'"
            Using conn As New OleDbConnection(cn),
                   cmd As New OleDbCommand(sql, conn)
                conn.Open()
                cmd.ExecuteNonQuery()
            End Using
        Catch myerror As Exception
            MessageBox.Show("Error: " & myerror.Message)
        End Try
    End Sub
    Private Sub SQL2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SQL2.Click
        InsertIntoGsdts()
        fillDataGridView1()
    End Sub

GSDTS IFGTS 输出 GSDTS

I found a solution according to the link below Here's a link !

Sub InsertIntoGsdts()
        Try
            Dim sql As String = "update GSDTS as t1 inner join IFGTS as t2 on t1.[ITM] = t2.[ITM] set t1.[CIU] = t2.[PRSOBNET] WHERE GDN = 'A.04.01.002.001'"
            Using conn As New OleDbConnection(cn),
                   cmd As New OleDbCommand(sql, conn)
                conn.Open()
                cmd.ExecuteNonQuery()
            End Using
        Catch myerror As Exception
            MessageBox.Show("Error: " & myerror.Message)
        End Try
    End Sub
    Private Sub SQL2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SQL2.Click
        InsertIntoGsdts()
        fillDataGridView1()
    End Sub



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