Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
Try
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
da = New OleDbDataAdapter("SELECT * FROM Stock1", con)
da.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
DataGridView1.Columns(0).Visible = True
DataGridView1.Columns(1).Visible = True
DataGridView1.Columns(2).Visible = True
DataGridView1.Columns(3).Visible = False
DataGridView1.Columns(4).Visible = False
DataGridView1.Columns(5).Visible = True
DataGridView1.Columns(6).Visible = False
DataGridView1.Columns(7).Visible = False
DataGridView1.Columns.Item(0).Width = 50
DataGridView1.Columns.Item(1).Width = 100
DataGridView1.Columns.Item(2).Width = 80
DataGridView1.Columns.Item(5).Width = 100
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
End Try
End Sub
โค้ดปุ่มบันทึก Code (VB.NET)
Try
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection
con.Open()
End If
cmd.Connection = con
'check whether add new or update
If Me.semat.Tag & "" = "" Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO Tb_History(His_products, His_quantity, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Me.txtnum.Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Me.txttime.Text & "')"
cmd.ExecuteNonQuery()
MessageBox.Show("บันทึกลงตารางเรียบร้อยแล้ว")
'refresh data in list
RefreshData()
'close connection
con.Close()
End If
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " & ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
If DataGridView1.Columns(5).Visible <= 0 > True Then
MsgBox("ไม่สามารถบันทึกได้")
Else
'check whether add new or update
If Me.semat.Tag & "" = "" Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO Tb_History(His_products, His_quantity, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Me.txtnum.Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Me.txttime.Text & "')"
cmd.ExecuteNonQuery()
MessageBox.Show("บันทึกลงตารางเรียบร้อยแล้ว")
'refresh data in list
RefreshData()
'close connection
con.Close()
End If
End If
Private Sub Button33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button33.Click
Dim rowindex As String
Dim found as Boolean = false
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells.Item("ITEM_ID").Value = TextBox5.Text Then
rowindex = row.Index.ToString()
found = true
Dim actie As String = row.Cells("PRICE").Value.ToString()
MsgBox(actie)
Exit for
End If
Next
If Not found Then
MsgBox("Item not found")
End if
End Sub