 |
|
ให้แสดงเฉพาะ ช่วงเวลาที่เราเลือก ซึ่งตอนนี้ก็แสดงขึ้นมา แต่ไม่ถูกต้องอะครับ |
|
 |
|
|
 |
 |
|

อยากให้หน้านี้โชว์ตามช่วงเวลาที่กำหนดอะครับ แบบไม่ข้ามเดือนด้วยอะครับ
คือในฐานข้อมูลเก็บค่าแบบ .ToShortDateString() อะครับ คือ 1/12/2554
Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Public Class frm_Transaction
Dim Conn As OleDbConnection
Private dataset As DataSet
Private cmd As OleDbCommand
Private objDataAdapter As OleDbDataAdapter
Private objDataTable As DataTable
Dim ck As String
Private Sub frm_Transaction_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblText.Text = "ชนิดการทำรายการ : R = Receive การรับเข้าสินค้า A = Adjust การปรับยอดสินค้า B = Billing ออกบิลจ่ายสินค้า"
Conn = New OleDbConnection(conStr)
Conn.Open()
btnSearch.Enabled = False
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
If (RbtnR.Checked = True) Then
ck = "R"
ReadData()
ElseIf (RbtnB.Checked = True) Then
ck = "B"
ReadData()
ElseIf (RbtnA.Checked = True) Then
ck = "A"
ReadData()
ElseIf (RbtnRB.Checked = True) Then
ReadDataAB()
ElseIf (RbtnAll.Checked = True) Then
ReadDataAll()
End If
FillDataGridView()
End Sub
Private Sub ReadDataAll()
Dim sql As String = ""
sql = "SELECT TransactionStore.EnterDate, TransactionStore.Type, TransactionStore.ItemCode, Item.ItemName, Lot.LotNo, Location.LocName, Store.StoreName, TransactionStore.Qty, TransactionStore.TotalCost, "
sql &= "Employee.EmployeeName, TransactionStore.UserID FROM (((((TransactionStore LEFT JOIN Item ON TransactionStore.ItemCode = Item.ItemCode) "
sql &= "LEFT JOIN Lot ON TransactionStore.LotNo = Lot.LotNo) "
sql &= "LEFT JOIN Location ON Lot.LocID = Location.LocID) "
sql &= "LEFT JOIN Store ON Location.StoreID = Store.StoreID) "
sql &= "LEFT JOIN Employee ON TransactionStore.EmployeeCode = Employee.EmployeeCode) ORDER BY TransactionStore.EnterDate ASC"
cmd = New OleDbCommand(sql, Conn)
Dim adapter As New OleDbDataAdapter(cmd)
dataset = New DataSet()
adapter.Fill(dataset, "cust")
End Sub
Private Sub ReadData()
Dim sql As String = ""
sql = "SELECT TransactionStore.EnterDate, TransactionStore.Type, TransactionStore.ItemCode, Item.ItemName, Lot.LotNo, Location.LocName, Store.StoreName, TransactionStore.Qty, TransactionStore.TotalCost, "
sql &= "Employee.EmployeeName, TransactionStore.UserID FROM (((((TransactionStore LEFT JOIN Item ON TransactionStore.ItemCode = Item.ItemCode) "
sql &= "LEFT JOIN Lot ON TransactionStore.LotNo = Lot.LotNo) "
sql &= "LEFT JOIN Location ON Lot.LocID = Location.LocID) "
sql &= "LEFT JOIN Store ON Location.StoreID = Store.StoreID) "
sql &= "LEFT JOIN Employee ON TransactionStore.EmployeeCode = Employee.EmployeeCode) WHERE (TransactionStore.EnterDate >= #" & DtpStart.Value.ToShortDateString & "#) AND (TransactionStore.EnterDate <= #" & DtpEnd.Value.ToShortDateString & "#) AND (TransactionStore.Type = '" & ck & "') ORDER BY TransactionStore.EnterDate ASC"
cmd = New OleDbCommand(sql, Conn)
Dim adapter As New OleDbDataAdapter(cmd)
dataset = New DataSet()
adapter.Fill(dataset, "cust")
End Sub
Private Sub ReadDataAB()
Dim sql As String = ""
sql = "SELECT TransactionStore.EnterDate, TransactionStore.Type, TransactionStore.ItemCode, Item.ItemName, Lot.LotNo, Location.LocName, Store.StoreName, TransactionStore.Qty, TransactionStore.TotalCost, "
sql &= "Employee.EmployeeName, TransactionStore.UserID FROM (((((TransactionStore LEFT JOIN Item ON TransactionStore.ItemCode = Item.ItemCode) "
sql &= "LEFT JOIN Lot ON TransactionStore.LotNo = Lot.LotNo) "
sql &= "LEFT JOIN Location ON Lot.LocID = Location.LocID) "
sql &= "LEFT JOIN Store ON Location.StoreID = Store.StoreID) "
sql &= "LEFT JOIN Employee ON TransactionStore.EmployeeCode = Employee.EmployeeCode) WHERE (TransactionStore.Type = '" & "R" & "' OR TransactionStore.Type = '" & "B" & "') ORDER BY TransactionStore.EnterDate ASC"
cmd = New OleDbCommand(sql, Conn)
Dim adapter As New OleDbDataAdapter(cmd)
dataset = New DataSet()
adapter.Fill(dataset, "cust")
End Sub
Tag : .NET, Ms Access, Win (Windows App), VS 2005 (.NET 2.x)
|
|
 |
 |
 |
 |
Date :
2011-03-26 03:31:27 |
By :
AddbbA |
View :
1589 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ SQL BETWEEN ดีกว่าครับ ตรวจสอบ Format ให้ถูกด้วยน่ะครับ
|
 |
 |
 |
 |
Date :
2011-03-26 07:00:48 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เง้อ ในเมื่อใน Data เก็บแบบ Short แล้วใน datetimepicker ที่ใช้ค้นหาเป็นแบบ Long ละ ทำไม
ไม่เปลี่ยนเป็นแบบ Short ละครับ แบบนี้มันจะหาเจอเหรอคับ
|
 |
 |
 |
 |
Date :
2011-03-26 10:59:48 |
By :
angelrings0 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ใช้ Code แบบนี้อะครับ แต่รู้สึกว่า มันจะได้แต่วันที่อะครับ
Code (VB.NET)
Private Sub ReadData()
Dim sql As String = ""
sql = "SELECT TransactionStore.EnterDate, TransactionStore.Type, TransactionStore.ItemCode, Item.ItemName, Lot.LotNo, Location.LocName, Store.StoreName, TransactionStore.Qty, TransactionStore.TotalCost, "
sql &= "Employee.EmployeeName, TransactionStore.UserID FROM (((((TransactionStore LEFT JOIN Item ON TransactionStore.ItemCode = Item.ItemCode) "
sql &= "LEFT JOIN Lot ON TransactionStore.LotNo = Lot.LotNo) "
sql &= "LEFT JOIN Location ON Lot.LocID = Location.LocID) "
sql &= "LEFT JOIN Store ON Location.StoreID = Store.StoreID) "
sql &= "LEFT JOIN Employee ON TransactionStore.EmployeeCode = Employee.EmployeeCode) WHERE (format(TransactionStore.EnterDate,'ddmmyyyy') BETWEEN format(#" & DtpStart.Value.ToShortDateString & "#,'dd/mm/yyyy') AND format(#" & DtpEnd.Value.ToShortDateString & "#,'ddmmyyyy')) AND (TransactionStore.Type = '" & ck & "') ORDER BY TransactionStore.EnterDate ASC"
cmd = New OleDbCommand(sql, Conn)
Dim adapter As New OleDbDataAdapter(cmd)
dataset = New DataSet()
adapter.Fill(dataset, "cust")
End Sub
|
 |
 |
 |
 |
Date :
2011-03-26 13:59:01 |
By :
AddbbA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คับรู้ แต่ทำมัย ไม่เช็คให้ Datatimepicker เป็นแบบนี้ละครับ

มันจะได้ค้นหาได้ตรงกัน มันคนละแบบจะหากันเจอป่าวนั้น ไม่รู้ว่าเข้าใจผิดป่าวนะ
แต่จิง ๆ แล้วมันน่าจะเป็นแบบนี้นะคับ
แต่อีกอย่างขอดู code ในส่วนของการ Search หน่อย ว่าเป็นงั้ย บ้างที่อาจจะค้นหาแค่ ช่วงเดียวก่าได้
|
ประวัติการแก้ไข 2011-03-26 15:04:47
 |
 |
 |
 |
Date :
2011-03-26 15:02:27 |
By :
angelrings0 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 6 เขียนโดย : angelrings0 เมื่อวันที่ 2011-03-26 15:02:27
รายละเอียดของการตอบ ::
ลองเปลี่ยนมาใช้แบบที่บอกแล้วนะครับ แต่มันก็ติดตรงที่มันแสดงของเดือนอื่นด้วยอะครับ

นี้โค้ดอะครับ ที่ค้นหาอะครับ
Code (VB.NET)
Private Sub ReadData()
Dim sql As String = ""
sql = "SELECT TransactionStore.EnterDate, TransactionStore.Type, TransactionStore.ItemCode, Item.ItemName, Lot.LotNo, Location.LocName, Store.StoreName, TransactionStore.Qty, TransactionStore.TotalCost, "
sql &= "Employee.EmployeeName, TransactionStore.UserID FROM (((((TransactionStore LEFT JOIN Item ON TransactionStore.ItemCode = Item.ItemCode) "
sql &= "LEFT JOIN Lot ON TransactionStore.LotNo = Lot.LotNo) "
sql &= "LEFT JOIN Location ON Lot.LocID = Location.LocID) "
sql &= "LEFT JOIN Store ON Location.StoreID = Store.StoreID) "
sql &= "LEFT JOIN Employee ON TransactionStore.EmployeeCode = Employee.EmployeeCode) WHERE (format(TransactionStore.EnterDate,'ddmmyyyy') BETWEEN format(#" & DtpStart.Value.ToShortDateString & "#,'ddmmyyyy') AND format(#" & DtpEnd.Value.ToShortDateString & "#,'ddmmyyyy')) AND (TransactionStore.Type = '" & ck & "') ORDER BY TransactionStore.EnterDate ASC"
cmd = New OleDbCommand(sql, Conn)
Dim adapter As New OleDbDataAdapter(cmd)
dataset = New DataSet()
adapter.Fill(dataset, "cust")
End Sub
|
 |
 |
 |
 |
Date :
2011-03-26 15:48:23 |
By :
AddbbA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|