我有这个代码从vb.net中获取最后2个数据从访问数据库到列表视图,但是这给了我错误
这是我的代码:
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
这是错误:
IErrorInfo.GetDescription因E_FAIL(0x80004005)而失败。
我该怎么做。
答案 0 :(得分:0)
dim ds as new DataSet();
dim adapter as new OleDataDataAdapter("SELECT * FROM pay_pretalk
WHERE sdate > DateAdd("m", -2, Date())", con);
adapter.Fill(ds);
dt = ds.Tables[0];
.....