Imports System.Data.OleDb
Public Class Form1
Dim objConnection As OleDbConnection
Dim objCmd As OleDbCommand
Dim strConnection As String
Dim adapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=D:\PC_CNC.accdb"
' Create and open the connection object
objConnection = New OleDbConnection(strConnection)
objConnection.Open()
' Create the Command and set its properties
objCmd = New OleDbCommand()
objCmd.Connection = objConnection
objCmd.CommandText = "querypositive" ' ชื่อ procedure
'objCmd.Parameters.Add(New OleDbParameter("@param", "xxx")) 'กรณีที่มี parameter (รับตัวแปร)
objCmd.CommandType = CommandType.StoredProcedure
adapter.SelectCommand = objCmd
adapter.Fill(ds)
dt = ds.Tables(0)
'If (dt.Rows.Count > 0) Then
'For index = 0 To dt.Rows.Count - 1
'Console.WriteLine(dt.Rows(index)(0))
'Next
dgv1.DataSource = dt
'End If
'Console.ReadLine()
If dgv1.RowCount > 1 Then
Dim TotalPrice As Integer = 0
For index As Integer = 0 To dgv1.RowCount - 1
TotalPrice += Convert.ToInt32(dgv1.Rows(index).Cells(8).Value)
Next
txt1.Text = Format$(TotalPrice, "###,###,###,###")
End If
cb1.DataSource = ds.Tables(0)
cb1.DisplayMember = "Vender"
ListBox1.DataSource = ds.Tables(0)
ListBox1.ValueMember = "ToolNumberID"
ListBox2.DataSource = ds.Tables(0)
ListBox2.ValueMember = "Totall"
ListBox3.DataSource = ds.Tables(0)
ListBox3.ValueMember = "Price"
ListBox4.DataSource = ds.Tables(0)
ListBox4.ValueMember = "Total Price"
Tag : .NET, Ms Access, VB.NET, VS 2012 (.NET 4.x), Windows