Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

樣品單資料庫除錯_1.vb 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 樣品單資料庫除錯_1
  4. Dim conn As New SqlConnection
  5. Dim da As New SqlDataAdapter
  6. Dim cmd As New SqlCommand
  7. Dim ds As New DataSet
  8. Dim dr As SqlDataReader
  9. Private Sub Set_DGV1載入前設定()
  10. DataGridView1.DataSource = Nothing : ds.Clear()
  11. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  12. DataGridView1.ColumnHeadersHeight = 25
  13. DataGridView1.AllowUserToAddRows = False
  14. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  15. End Sub
  16. Private Sub Set_DGV1載入後設定()
  17. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
  18. End Sub
  19. Private Sub Set_清單()
  20. Set_DGV1載入前設定()
  21. SQL1 = "SELECT 樣品訂單部件表.SO, 樣品訂單部件表.流水號, 樣品訂單清單.流水號 AS 流水號2, 樣品訂單清單.SO AS SO2
  22. FROM 樣品訂單部件表 LEFT OUTER JOIN 樣品訂單清單 ON 樣品訂單部件表.流水號 = 樣品訂單清單.流水號 AND 樣品訂單部件表.版次 = 樣品訂單清單.版次 AND 樣品訂單部件表.SO = 樣品訂單清單.SO
  23. WHERE (樣品訂單清單.SO IS NULL) ORDER BY SO2"
  24. Set_DGV1載入後設定()
  25. End Sub
  26. Private Sub Set_grid()
  27. DataGridView1.Columns(0).Width = 120 : DataGridView1.Columns(1).Width = 120 : DataGridView1.Columns(2).Width = 120 : DataGridView1.Columns(3).Width = 120
  28. End Sub
  29. Private Sub 樣品單資料庫除錯_1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  30. Set_清單()
  31. End Sub
  32. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  33. If e.RowIndex = -1 Then : Else
  34. TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString
  35. TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
  36. End If
  37. End Sub
  38. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  39. If TextBox1.Text = "" Then
  40. MsgBox("沒有選擇要刪除的資料")
  41. Else
  42. Dim aa As MsgBoxResult
  43. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  44. If aa = MsgBoxResult.Ok Then
  45. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  46. SQL1 = "DELETE FROM 樣品訂單部件表 WHERE (SO LIKE N'" & TextBox1.Text & "' AND 流水號 LIKE N'" & TextBox2.Text & "')"
  47. cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
  48. MsgBox("刪除完成") : Set_清單()
  49. End If
  50. End If
  51. End Sub
  52. End Class