【发布时间】:2016-04-11 17:43:39
【问题描述】:
我正在使用带有 Microsoft Access 的 VB.NET。
我创建的函数有问题。我只希望函数返回一个充满信息的 DataTable 来制作我的报告,并使用我给出的参数。我正在使用Between子句...我首先认为子句“Between”不适用于Access(如“Limit”),但我在Access中创建了一个查询,并且效果很好!
看到这个,我得出的结论是,由于某种原因,我的 OleDbDataAdapter 没有按照应有的方式填充我的 DataTable ...我不明白为什么,因为我遵循与其他函数相同的模式(使用不同的查询,显然)。
函数的代码是这样的:
Protected Friend Function reporte(ByVal tipo As String, ByVal fechInicio As String, ByVal fechFinal As String) As DataTable
Dim cmd As String = ""
Dim p As New DataTable
If (tipo.Equals("general")) Then
cmd = "Select Cod_Producto,Serial,Lotpallet,Fecha_Ingreso,Producto,Modelo,Descripcion,Precio,Cantidad From Productos WHERE Fecha_Ingreso BETWEEN '[" & fechInicio & "]' AND '[" & fechFinal & "]'"
ElseIf (tipo.Equals("por producto")) Then
cmd = "Select Cod_Producto,Serial,Lotpallet,Fecha_Ingreso,Producto,Modelo,Descripcion,Precio,Cantidad From Productos WHERE Producto='[" & PantallaPrincipal.REP.ComboModel.SelectedItem & "]' AND Fecha_Ingreso BETWEEN '[" & fechInicio & "]' AND '[" & fechFinal & "]'"
End If
Try
con.Open()
adapter = New OleDbDataAdapter(cmd, con)
adapter.Fill(p)
adapter.Dispose()
comando.Dispose()
con.Close()
Catch ex As Exception
con.Close()
MsgBox("Problemas en la consulta: " + ex.Message(), MsgBoxStyle.Critical)
End Try
Return p
End Function
可能是什么问题?
【问题讨论】:
-
我已经用过了,但没用。另外,我的表单没有用于执行 SQL 注入的文本框...
-
我按照你说的做了测试,是的,我的变量在我编程时成功存储了数据
-
日期正在存储,我的查询也是
-
看!适配器未能填充 DataTable! i.imgur.com/cawSQnK.png
标签: vb.net ms-access datatable