Imports System.Data
Imports System.Data.OleDb
Public Class FrmSell
Dim constr As String = "Provider=Microsoft.jet.OLEDB.4.0;Data source=DatabaseFinal.mdb"
Dim conn As OleDbConnection
Dim ds As New DataSet
Private Sub FrmSell_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = New OleDbConnection(constr)
conn.Open()
showtt()
Showee()
com()
End Sub
Sub Showee()
Dim strsQL As String = "SELECT * FROM Product ORDER BY P_ID ASC "
Dim objAdapter As New OleDbDataAdapter(strsQL, conn)
objAdapter.Fill(ds, "database.mdb")
Dim objDataview As New DataView(ds.Tables("database.mdb"))
DataGridView1.DataSource = objDataview
Me.DataGridView1.Columns(0).HeaderText = "รหัสสินค้า"
Me.DataGridView1.Columns(1).HeaderText = "ชื่อสินค้า"
Me.DataGridView1.Columns(2).HeaderText = "รายละเอียด"
Me.DataGridView1.Columns(3).HeaderText = "ราคาสินค้า"
Me.DataGridView1.Columns(4).HeaderText = "จำนวนสินค้า"
Me.DataGridView1.Columns(5).HeaderText = "ประเภทสินค้า"
Me.DataGridView1.Columns(1).Width = 201
Dim showdate As String = String.Format("{0:dd/MM/yyyy}", DateTime.Now)
TextBox9.Text = showdate
End Sub
Sub showtt()
Dim S1 As New OleDbDataAdapter("Select * from sell ", conn)
Dim S2 As New DataTable
S1.Fill(S2)
DataGridView2.DataSource = S2
Me.DataGridView2.Columns(0).HeaderText = "รหัสลูกค้า"
Me.DataGridView2.Columns(1).HeaderText = "รหัสพนักงาน"
Me.DataGridView2.Columns(2).HeaderText = "ชื่อสินค้า"
Me.DataGridView2.Columns(3).HeaderText = "ราคา"
Me.DataGridView2.Columns(4).HeaderText = "จำนวน"
Me.DataGridView2.Columns(5).HeaderText = "ส่วนลด"
Me.DataGridView2.Columns(6).HeaderText = "ยอดรวม"
Me.DataGridView2.Columns(7).HeaderText = "วันที่"
For i As Integer = 0 To Me.DataGridView2.ColumnCount - 1
Me.DataGridView2.Columns(i).Width = 100
Next
End Sub
Sub com()
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value
TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
End Sub
End Class
Tag : .NET, VB.NET
Date :
2014-02-17 01:24:38
By :
นายฟู
View :
1216
Reply :
3
No. 1
Guest
เรียกข้อมูลตารางลูกค้า ประมาณนี้นะครับ
Code (VB.NET)
Dim strsQL As String = "SELECT * FROM Customers(ชื่อตารางลูกค้า) ORDER BY CustomersID ASC "
Dim objAdapter As New OleDbDataAdapter(strsQL, conn)
objAdapter.Fill(ds, "Cus")
For number As Double = 1 To ds.tables("Cus").rowcount
Combobox(ชื่อคอมโบบ๊อก).items.add(ds.tables("Cus").row(number-1)(name) << วน for เอาชื่อเติมลง combobox
Next
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
showdata()
'ดึงข้อมูลแบบ StringBuilder มาโชว์ใน Combobox
'--1 Connect
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open()
End With
'--2 Sql
Dim sb As New StringBuilder
sb.Remove(0, sb.Length)
sb.Append("Select * From Brands;")
sb.Append("Select * From Categorys;")
Dim s As String = sb.ToString
'--3 Exe
Dim cm As New SqlCommand(s, cn)
Dim dr As SqlDataReader
dr = cm.ExecuteReader
'--4 ดึงข้อมูล
Dim dt1 As New DataTable
dt1.Load(dr)
With CbbBrand
.DisplayMember = "BrandName"
.ValueMember = "BrandID"
.DataSource = dt1
End With
Dim dt2 As New DataTable
dt2.Load(dr)
With CbbCate
.DisplayMember = "CategoryName"
.ValueMember = "CategoryID"
.DataSource = dt2
End With