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")
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()
'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"))
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?