Solved

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

Posted on 2010-09-09
2
652 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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