我使用后端作为MS Access 2013,当我执行函数时它在消息框中返回0但我在sql模式下在Access 2013中执行相同的查询它返回多行。问题是这个函数返回0的原因数据集表中的行。它应该返回一些行
表格
票据(bill_id,M_ID,日期,OWNERNAME,OLDVALUE,NEWVALUE,单位,OTH,rcharges,billamount)
米(M_ID,m_type,OWNERNAME,flatno,指定,资格,部门)
Private Sub frmViewStatementReport_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Billrpt As New RptBillStatement
Billrpt.Load(Application.StartupPath & "\RptBillStatement.rpt")
Try
Dim qry As String
' I have Tried the above both queries but returns 0 rows in table(0).
qry = "SELECT bills.ownername as Name, meters.designation as des, meters.department as depart, bills.billAmount as amount FROM bills LEFT JOIN meters ON meters.m_id =bills.m_id WHERE bills.dated like '*-jan-*'"
'qry = "SELECT bt.bill_id,bt.ownername as Name, mt.designation as designation, mt.department as department,bt.billAmount as billAmount FROM bills AS bt INNER JOIN meters AS mt ON bt.m_id = mt.m_id WHERE bt.dated like '*-jan-*'"
Using conn = New OleDbConnection(ConString)
Using daa As OleDbDataAdapter = New OleDbDataAdapter(qry, conn)
Using dss As DataSet = New DataSet
conn.Open()
daa.Fill(dss, "Bills")
Dim dt As New DataTable
dt = ds.Tables(0)
Billrpt.SetDataSource(ds.Tables(0))
Me.CrystalReportViewer1.Refresh()
Me.CrystalReportViewer1.ReportSource =Billrpt
MsgBox(dss.Tables(0).Rows.Count.ToString)
conn.Close()
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
答案 0 :(得分:0)
通配符实际上是带有Like子句的'%%'而不是'**'
WHERE bills.dated like '%-jan-%'"
应该解决您的问题。