Solved

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

Posted on 2010-09-09
2
646 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

943 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

11 Experts available now in Live!

Get 1:1 Help Now