Solved

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

Posted on 2010-09-09
2
643 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
Comment Utility
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
Comment Utility
Oh for fu....

Thank you!!!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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