If dgvdata.Rows.Count > 0 Then
If dgvdata.SelectedRows.Count > 0 Then
Dim intpid As Integer = dgvdata.SelectedRows(0).Cells(0).Value
If Not conn.State = ConnectionState.Open Then
conn.Open()
End If
Dim cmd As New OleDb.OleDbCommand
Dim sql As String
sql = "DELETE * FROM produce WHERE pid = " & intpid
cmd.Connection = conn
cmd.CommandText = sql
cmd.ExecuteNonQuery()
conn.Close()
Refreshdata()
End If
End If
อันนี้เรียกข้อมูลมาในDataGridView
Code (VB.NET)
ConnectDB()
Dim intfid As Integer
intfid = lbid.Text
Dim da As New OleDb.OleDbDataAdapter("Select pid as[รหัส], pd as[วันที่ผลิต], pu as[จำนวน] From produce Where fid=" & intfid, conn)
Dim dt As New DataTable
da.Fill(dt)
dgvdata.DataSource = dt
conn.Close()
ConnectDB()
Dim intfid As Integer
intfid = lbid.Text
Dim da As New OleDb.OleDbDataAdapter("Select pid as[รหัส], pd as[วันที่ผลิต], pu as[จำนวน] From produce Where fid=" & intfid, conn)
Dim dt As New DataTable
da.Fill(dt)
dgvdata.DataSource = dt
>>>> Me.dgvdata.Columns(0).Visible = False
conn.Close()