HOME > .NET Framework > Forum > vb.net DateTimePicker มันไม่ขึ้นเลย Button1.Click DataGridView1.DataSource = Database("SELECT * FROM Sale WHERE dates = " & DateTimePicker1.Value.Date & "").Tables(0)
vb.net DateTimePicker มันไม่ขึ้นเลย Button1.Click DataGridView1.DataSource = Database("SELECT * FROM Sale WHERE dates = " & DateTimePicker1.Value.Date & "").Tables(0)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataGridView1.DataSource = Database("SELECT * FROM Sale WHERE dates = " & DateTimePicker1.Value.Date & "").Tables(0)
End Sub
นี่ครับโค้ด
' ตัวอย่าง
' Database("Select * From Sale")
Code (VB.NET)
Public Shared Function Database(ByVal SqlCommand As String) As DataSet
Dim oConn As OleDbConnection
Dim oComm As OleDbCommand
Dim oData As OleDbDataAdapter
Dim resultSet As New DataSet
Dim oConnect, oQuery As String
oConnect = "Provider = Microsoft.JET.OLEDB.4.0; Data Source = Database/Database.mdb"
oQuery = SqlCommand
oConn = New OleDbConnection(oConnect)
oComm = New OleDbCommand(oQuery, oConn)
oData = New OleDbDataAdapter(oQuery, oConn)
Try
oConn.Open()
oData.Fill(resultSet)
oConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "ข้อผิดพลาด")
End Try
Return resultSet
End Function