Solved

Filling an OleDbDataSet from an OleDataAdapter in Visual Basic 2010 using an SQL SELECT Command

Posted on 2010-09-09
2
651 Views
Last Modified: 2012-06-27
Dear Experts,

I am hoping you can help.

I have mainly been coding in VB6, but felt that a move to .Net was well overdue and have grabbed a copy of the Express Version of Visual Basic 2010 and a text book.

I have now encountered a problem trying to create unbound data connections.

In VB6 I found this quite simple - declare your connection, open it, declare your recordset, opening with your chosen command text to fill the recodset with the relevant data from the database.

Trying to do the same sort of thing in .net I have written the following code:

 
'Declare Connection and set connection string
                Dim ClientCompaniesConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=S:\SimonEvans\Visual Basic Programs\IncorpDB\Incorporation Database.mdb")
                'Declare Adapter
                Dim ClientCompaniesDataAdapter As New OleDbDataAdapter

                'Set the CommandText for the Adapter and tell to connect to ClientCompaniesConnection
                ClientCompaniesDataAdapter.SelectCommand = New OleDbCommand
                ClientCompaniesDataAdapter.SelectCommand.Connection = ClientCompaniesConnection
                ClientCompaniesDataAdapter.SelectCommand.CommandText = "SELECT * FROM EIncCompanies WHERE ClientCode = '" & SearchString & "'"

                'Declare the DataSet and Fill from the Adapter
                Dim ClientCompaniesDataSet As DataSet = New DataSet()
                ClientCompaniesDataAdapter.Fill(ClientCompaniesDataSet, "EIncCompanies")

                'Declare the DataView
                Dim ClientCompaniesDataView = New DataView(ClientDataSet.Tables("EIncCompanies"))
                'Check the count and then show the first record if there is one (just to check it works)
                If ClientCompaniesDataView.Count > 0 Then MsgBox(ClientCompaniesDataView(0).Item("Companyname"))

Open in new window


This is not working as I expected it to.

The DataView.Count is 0 despite there being records in the database that match the searchstring.

I have tried removing the 'WHERE...' part of the Command Text so that it should return everything within the table. The Count is still 0.

I tried doing the same with another table within the database (that also includes a Field of the same name) and that returns every record in the database, even when I include the 'WHERE' part of the Command Text.

i am clearly foing something wrong, but i do not know what.

Please, can anyone help?

Thanks

Sim.
0
Comment
Question by:Simon482
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33634436
I hope it's just a typo :)
change
Dim ClientCompaniesDataView = New DataView(ClientDataSet.Tables("EIncCompanies"))
into
Dim ClientCompaniesDataView = New DataView(ClientCompaniesDataSet.Tables("EIncCompanies"))

Also can you check the following before executing this:
Dim ClientCompaniesDataView = New DataView(ClientDataSet.Tables("EIncCompanies"))

(ClientCompaniesDataSet.Tables(0).Rows.Count)
0
 

Author Closing Comment

by:Simon482
ID: 33634457
Oh for fu....

Thank you!!!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 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