.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 2nd, 2003, 07:29 PM
neuralSea neuralSea is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 15 neuralSea User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old December 4th, 2003, 11:01 AM
vinidel vinidel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Virginia
Posts: 19 vinidel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old December 8th, 2003, 04:09 PM
neuralSea neuralSea is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 15 neuralSea User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thankyou.

Thankyou Vinidel. I couldn't see the wood for the trees. Thanks for picking it up.

Cheers,

NeuralSea

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Why does this code fail reading an Access DB with VB .NET?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT