'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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jack |