none
update the databases after use the union query RRS feed

  • Question

  • i want to update the databases after  use the union query

    union  code

    Dim cmd As OleDbCommand = New OleDbCommand("SELECT ID_TB1,TYPE_TB1 ,COUN_TB1 FROM tb1 UNION SELECT ID_TB2,TYPE_TB2 ,COUN_TB2 FROM tb2 UNION SELECT ID_TB3,TYPE_TB3 ,COUN_TB3 FROM tb3", con)
           con.Open()
           DataAdapter1 = New OleDbDataAdapter(cmd)
           Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(DataAdapter1)
           DataSet1 = New DataSet()
           DataAdapter1.Fill(DataSet1, "tb1,tb2,tb3")
           DataGridView1.DataSource = DataSet1
           DataGridView1.DataMember = "tb1,tb2,tb3"

    update code not work

    Dim DataAdapter As New OleDbDataAdapter("SELECT ID_TB1,TYPE_TB1 ,COUN_TB1,LOSS_TB1,RETURN_TB1 FROM

    tb1 UNION SELECT ID_TB2,TYPE_TB2 ,COUN_TB2,LOSS_TB2,RETURN_TB2 FROM tb2 UNION SELECT

    ID_TB3,TYPE_TB3 ,COUN_TB3,LOSS_TB3,RETURN_TB3 FROM tb3", con) DataSet1.Clear() DataAdapter.Fill(DataSet1, "TB1,TB2,TB3") DataGridView1.Refresh() conn() count() If con.State = ConnectionState.Open Then con.Close() End If

    another way not work

     Sub UPDAT()
            On Error Resume Next
            con.Open()
            Dim Sav As New OleDb.OleDbCommand
            Sav.Connection = con
            Sav.CommandType = CommandType.Text
            Sav.CommandText = "UPDATE TB1 SET  TYPE_TB1 = '" & _
            stock_add.TextBox1.Text & "' ,COUN_TB1 = '" & _
            stock_add.TextBox2.Text & "' where ID_TB1 LIKE '" & _
            stock_add.Label6.Text & "'"
            Sav.ExecuteNonQuery()
    
            '================
            Dim Sav1 As New OleDb.OleDbCommand
            Sav1.Connection = con
            Sav1.CommandType = CommandType.Text
            Sav1.CommandText = "UPDATE TB2 SET  TYPE_TB2 = '" & _
            stock_add.TextBox1.Text & "' ,COUN_TB2 = '" & _
            stock_add.TextBox2.Text & "' where ID_TB2 LIKE '" & _
            stock_add.Label6.Text & "'"
            Sav1.ExecuteNonQuery()
            '================
            Dim Sav2 As New OleDb.OleDbCommand
            Sav2.Connection = con
            Sav2.CommandType = CommandType.Text
            Sav2.CommandText = "UPDATE TB3 SET  TYPE_TB3 = '" & _
            stock_add.TextBox1.Text & "' ,COUN_TB3 = '" & _
            stock_add.TextBox2.Text & "' where ID_TB3 LIKE '" & _
            stock_add.Label6.Text & "'"
            Sav2.ExecuteNonQuery()
            con.Open()
            Dim DataAdapter As New OleDbDataAdapter("SELECT ID_TB1,TYPE_TB1 ,COUN_TB1,LOSS_TB1,RETURN_TB1 FROM tb1 UNION SELECT ID_TB2,TYPE_TB2 ,COUN_TB2,LOSS_TB2,RETURN_TB2 FROM tb2 UNION SELECT ID_TB3,TYPE_TB3 ,COUN_TB3,LOSS_TB3,RETURN_TB3 FROM tb3", con)
            DataSet1.Clear()
            BindingSource1.EndEdit()
            DataAdapter.Fill(DataSet1, "TB1,TB2,TB3")
            DataGridView1.Refresh()
            conn()
            count()
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            MsgBox("update ok")

    Saturday, February 3, 2018 8:11 AM

Answers

All replies