?
Solved

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

Posted on 2010-09-09
2
Medium Priority
?
659 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

762 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