Answered by:
update the databases after use the union query

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")
- Moved by Dave PatrickMVP Saturday, February 3, 2018 2:17 PM
Saturday, February 3, 2018 8:11 AM
Answers
-
You have asked in the wrong forum. This forum is for questions and discussions about the forums themselves. Your question should probably be asked in a VB forum, such as here:
https://social.msdn.microsoft.com/Forums/en-US/home?forum=vbgeneral
Richard Mueller - MVP Enterprise Mobility (Identity and Access)
- Proposed as answer by Dave PatrickMVP Saturday, February 3, 2018 2:19 PM
- Marked as answer by Dave PatrickMVP Saturday, February 10, 2018 2:39 PM
Saturday, February 3, 2018 10:49 AM -
or also try them over here.
https://social.msdn.microsoft.com/Forums/windows/en-US/home?category=windowsforms
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP, Banned Saturday, February 10, 2018 1:54 PM
- Marked as answer by Dave PatrickMVP Saturday, February 10, 2018 2:39 PM
Saturday, February 3, 2018 2:19 PM
All replies
-
or also try them over here.
https://social.msdn.microsoft.com/Forums/windows/en-US/home?category=windowsforms
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP, Banned Saturday, February 10, 2018 1:54 PM
- Marked as answer by Dave PatrickMVP Saturday, February 10, 2018 2:39 PM
Saturday, February 3, 2018 2:19 PM