简体   繁体   English

SQL (INSERT INTO) 命令在 VB.NET 的 OLEDB 中不起作用

[英]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.我想在数据库“GSDTS”的“CIU”列中更新,并根据“ITM”列和“GDN”列的条件从“PRSOBNET”列中的数据库“IFGTS”中检索数据或值或仓库。 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?我是否必须进行 sql 更新或插入才能推荐解决方案,因为我在代码中的 sql 命令根本不起作用,sql 命令解决方案如何工作? 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



声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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