 |
|
[.NET]
add จาก 1 table แล้วไปลบจาก 1 table ในเวลาเดียวกัน |
|
 |
|
|
 |
 |
|
Code (VB.NET)
01. Private Sub Button1_Click(sender As Object , e As EventArgs) Handles Button1.Click
02.
03. connect.Open()
04. comm = New OleDbCommand( "insert into Table2(add_cas,add_firstname,add_lastname,add_department,add_extension,add_dater,add_description,add_stutus,add_solve,add_sig,add_date)values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox9.Text & "','" & TextBox6.Text & "','" & ComboBox1.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & Label12.Text & "')" , connect)
05. comm = New OleDbCommand( "DELETE * Table5 WHERE(ID = " & TextBox1.Text & ")" , connect)
06. comm.ExecuteNonQuery()
07.
08.
09. End If
10. connect.Close()
11. End Sub
12. End Class
รบกวนช่วยเช็ค code ให้หน่อยครับ คือผมอยากจะลบจาก table แล้วไป add เพิ่มอีก table ส่วน คอลัมน์ ID เป็นแบบ autonumber primary key บน access ครับไม่แน่ใจว่าผิดตรงไหนบ้างครับ
ปล คอลัมน์ทั้ง 2 ตารางไม่เท่ากันนะครับ
Tag : VB.NET
|
|
 |
 |
 |
 |
Date :
2017-03-10 14:51:03 |
By :
wathotza |
View :
895 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้การ INSERT SELECT ครับ
หรือถ้าจะทำด้วยการ Query เป็นพวก DataSet/DataTable แล้วค่อยมา Loop แล้ว Insert ก็ได้ครับ
|
 |
 |
 |
 |
Date :
2017-03-10 17:51:26 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คร่าวๆ นะครับ
Code (SQL)
01. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
02.
03. connect . Open ()
04. comm = New OleDbCommand( "insert into Table2(add_cas,add_firstname,add_lastname,add_department,add_extension,add_dater,add_description,add_stutus,add_solve,add_sig,add_date)values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox9.Text & "','" & TextBox6.Text & "','" & ComboBox1.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & Label12.Text & "')" , connect )
05. comm.ExecuteNonQuery() 'ไม่งั้น Insert ไม่ทำงานนะครับ
06. comm = New OleDbCommand( "DELETE * Table5 WHERE(ID = " & TextBox1.Text & ")" , connect )
07. comm.ExecuteNonQuery()
08.
09.
10. End If
11. connect . Close ()
12. End Sub
13. End Class
|
 |
 |
 |
 |
Date :
2017-03-10 18:39:01 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ๆทุกคนมากเลยครับ ตอนนี้สามารถทำได้แล้วครับ
|
 |
 |
 |
 |
Date :
2017-03-14 10:06:06 |
By :
wathotza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2017-03-14 11:03:08 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|