Imports System.Data
Imports System.Data.OleDb
Public Class frmOrderProducts
Dim cn As New OleDbConnection
Dim cm As New OleDbCommand
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim cal As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As String = "Provider = Microsoft.jet.oledb.4.0; Data Source = C:\infoproductsDB.mdb"
cn.ConnectionString = conn
cm.Connection = cn
End Sub
Private Sub DataGridView_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView.CellMouseUp
With DataGridView
Try
txtIDType.Text = .Rows.Item(e.RowIndex).Cells("IDType").Value
txtID.Text = .Rows.Item(e.RowIndex).Cells("ID").Value
txtNameType.Text = .Rows.Item(e.RowIndex).Cells("NameType").Value
txtName.Text = .Rows.Item(e.RowIndex).Cells("Name").Value
txtPriceUnit.Text = .Rows.Item(e.RowIndex).Cells("PriceUnit").Value
Catch ex As Exception
End Try
End With
End Sub
Public Sub SelectProductType()
DataGridView.Columns.Item(0).HeaderText() = "รหัสสินค้า"
DataGridView.Columns.Item(1).HeaderText() = "รหัสประเภทสินค้า"
DataGridView.Columns.Item(2).HeaderText() = "ชื่อประเภทสินค้า"
DataGridView.Columns.Item(3).HeaderText() = "ชื่อสินค้า"
DataGridView.Columns.Item(4).HeaderText() = "ราคาต่อหน่วย"
End Sub
Private Sub btNovel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btNovel.Click
cm.CommandText = "SELECT * FROM ProductsNovel"
da.SelectCommand = cm
da.Fill(ds, "ProductsNovel")
DataGridView.DataSource = ds.Tables("ProductsNovel")
SelectProductType()
End Sub
Private Sub btSStory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSStory.Click
cm.CommandText = "SELECT * FROM ProductsShortStory"
da.SelectCommand = cm
da.Fill(ds, "ProductsShortStory")
DataGridView.DataSource = ds.Tables("ProductsShortStory")
SelectProductType()
End Sub
Private Sub btCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCom.Click
cm.CommandText = "SELECT * FROM ProductsCom"
da.SelectCommand = cm
da.Fill(ds, "ProductsCom")
DataGridView.DataSource = ds.Tables("ProductsCom")
SelectProductType()
End Sub
Private Sub btCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCal.Click
cal = txtPriceUnit.Text * txtAmount.Text
txtCost.Text = cal
End Sub
Private Sub btClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btClear.Click
ds.Clear()
End Sub
Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
cm.CommandText = "INSERT INTO OrderProducts (IDOrder,CusID,Amount,CostTotal) values (" & txtSlip.Text & "," & txtCusID.Text & "," & txtAmount.Text & "," & txtCost.Text & ")"
cn.Open()
cm.ExecuteReader()
cn.Close()
MessageBox.Show("การบันทึกเสร็จเรียบร้อย", "ยืนยัน")
End Sub
End Class
ผลลัพธ์แบบฟอร์มที่ทำไว้คะ
รบกวนด้วยคะ ต้องแก้ Code ยังไงบ้างคะ
Tag : .NET, Ms Access, Win (Windows App), LINQ, VB.NET, VS 2008 (.NET 3.x)