Solved

Problem getting access to retrieve data from vb.net

Posted on 2016-10-19
6
29 Views
Last Modified: 2016-10-24
I have the following code in vb.net.  I do not get an error and if I copy mstr to access query it does return results, but from vb.net it returns 0 records.  Any Ideas.

thanks


Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        Dim mycriteria As String = BuildSearchCriteria()
        Dim dsSearch As New DataSet
        Dim daSearch As New OleDbDataAdapter
        Dim cmdSearch As New OleDbCommand
        Dim myConn As New OleDbConnection(mConn)
        Dim mStr As String = String.Empty
        mStr = "select a.propertyid ,a.bldgid,a.unitid, a.resiid,a.occufirstname, a.occulastname,b.FullID as ResidentFullID, "
        mStr = mStr & "b.Status,b.id,a.ResponsibleFlag, b.ListedDate,rtrim(a.OccuLastName)+', '+ RTRIM(a.OccuFirstName) as resiName, "
        mStr = mStr & "b.TotalAmt,b.OriginalAmt,b.CFeeAmt,b.CBY_AcctNo,   '' as resistatus from Occupants a left outer join Master b on "
        mStr = mStr & "a.PropertyId=b.PropertyID and a.BldgId=b.BldgID and a.UnitId=b.UnitID and a.ResiId=b.ResiID "
        mStr = mStr & mycriteria
        With cmdSearch
            .Connection = myConn
            .CommandText = mStr
            .CommandType = CommandType.Text
        End With
        daSearch.SelectCommand = cmdSearch
        daSearch.Fill(dsSearch)
        dgSearch.DataSource = dsSearch.Tables(0)



    End Sub

Open in new window

0
Comment
Question by:mgmhicks
  • 4
6 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 41850841
Check the content of myCriteria.
0
 

Author Comment

by:mgmhicks
ID: 41850913
below is the strings.  Again if I copy mstr to access it works.


myCriteria

Where a.occufirstname like 'jo*' and a.occulastname like 'davis*' "

mystr with mycriteria

"select a.propertyid ,a.bldgid,a.unitid, a.resiid,a.occufirstname, a.occulastname,b.FullID as ResidentFullID, b.Status,b.id,a.ResponsibleFlag, b.ListedDate,rtrim(a.OccuLastName)+', '+ RTRIM(a.OccuFirstName) as resiName, b.TotalAmt,b.OriginalAmt,b.CFeeAmt,b.CBY_AcctNo,   '' as resistatus from Occupants a left outer join Master b on a.PropertyId=b.PropertyID and a.BldgId=b.BldgID and a.UnitId=b.UnitID and a.ResiId=b.ResiID Where a.occufirstname like 'jo*' and a.occulastname like 'davis*' "
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41851078
Try using the AS syntax:

    from Occupants as a

/gustav
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:mgmhicks
ID: 41851155
Sorry that didn't do the trick Gustav.   Here is what it looks like now.  Again it works in access query.

 
select a.propertyid ,a.bldgid,a.unitid, a.resiid,a.occufirstname, a.occulastname,b.FullID as ResidentFullID, b.Status,b.id,a.ResponsibleFlag, b.ListedDate,rtrim(a.OccuLastName)+', '+ RTRIM(a.OccuFirstName) as resiName, b.TotalAmt,b.OriginalAmt,b.CFeeAmt,b.CBY_AcctNo,'' as resistatus from Occupants as a left outer join Master b on a.PropertyId=b.PropertyID and a.BldgId=b.BldgID and a.UnitId=b.UnitID and a.ResiId=b.ResiID Where a.occufirstname like 'jo*' and a.occulastname like 'davis*' 

Open in new window

0
 

Accepted Solution

by:
mgmhicks earned 0 total points
ID: 41851271
As it turns out they want you to use the % when you're using it from Vbnet so if I change the Asterick to a % then it works. thanks for your help
0
 

Author Closing Comment

by:mgmhicks
ID: 41856729
I came up with the solution
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now