|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Why does this code fail reading an Access DB with VB .NET?
This code will not work but I do not know why. Can someone please help?
'Add ListBox to a Form in VB.NET standard Edition 'connect ListBox to Access Database 'read a list of keywords from a Database table 'Keywords' 'Add list of keywords one by one to ListBox (with name 'lstData') 'Allow me to multiselect some of these keywords 'need to add multiselected items into keywords property 'of BuiltInDocumentProperties Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click ' CreateOleDbConnection Dim myQuery As String = "SELECT Keyword FROM keywords" Dim myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administration\My Documents\IWMDGP\keywords.mdb" ' myConnectionString is on one line Dim myConnection As New OleDbConnection(myConnectionString) Dim myCommand As OleDbCommand = New OleDbCommand(myQuery) myConnection.Open() Dim myReader As OleDbDataReader = myCommand.ExecuteReader Do While myReader.Read() lstData.Items.Add(myReader.GetString(0)) ' read data from Access Database and ' add to a ListBox with name lstData on a form Loop myReader.Close() myConnection.Close() End Sub 'Cheers, NeuralSea |
|
#2
|
|||
|
|||
|
You missed one parameter in your myCommand statement.
Dim myCommand As OleDbCommand = New OleDbCommand(myQuery) Try this Dim myCommand As OleDbCommand = New OleDbCommand(myQuery, myConnection) Its working for me. Good Luck |
|
#3
|
|||
|
|||
|
Thankyou.
Thankyou Vinidel. I couldn't see the wood for the trees. Thanks for picking it up.
Cheers, NeuralSea |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Why does this code fail reading an Access DB with VB .NET? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|