从访问数据库表中获取最后2个飞蛾数据 [英] Get the last 2 moths data from access database table
问题描述
我有这个代码从vb.net获取最后2个数据从访问数据库到列表视图,但是这给了我错误
这是我的代码:
我尝试了什么:
Public Sub showlistview ()
Dim dt As New DataTable
Dim ds作为新数据集
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter(SELECT * FROM pay_pretalk _
WHERE sdate> DATE_SUB(now(),INTERVAL 2 MONTH),con)
da。填充(dt)
Dim myrow As DataRow
For each myrow in dt.Rows
ListView1.Items.Add(myrow.Item(2) ))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(3))
ListView1.Items(ListView1.Items。 Count - 1).SubItems.Add(myrow.Item(4))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.It em(5))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(6))
ListView1.Items(ListView1 .Items.Count - 1).SubItems.Add(myrow.Item(7))
下一页
结束子
,这是错误
IErrorInfo.GetDescription失败了E_FAIL(0x80004005)。
i have this code for get the last 2 moth of data from access data base to list view in vb.net, but this give me error
this is my code:
What I have tried:
Public Sub showlistview()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter("SELECT * FROM pay_pretalk _
WHERE sdate > DATE_SUB(now(), INTERVAL 2 MONTH)", con)
da.Fill(dt)
Dim myrow As DataRow
For Each myrow In dt.Rows
ListView1.Items.Add(myrow.Item(2))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(3))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(4))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(5))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(6))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(7))
Next
End Sub
and this is the error
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
推荐答案
AFAIK没有这样的功能Access中的DATE_SUB。
你应该使用 DateAdd功能 - 访问 [ ^ ]
例如
AFAIK there is no such function DATE_SUB in Access.
You should use the DateAdd Function - Access[^]
E.g.
SELECT * FROM pay_pretalk
WHERE sdate < DateAdd("m", -2, now())
这篇关于从访问数据库表中获取最后2个飞蛾数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!