?
Solved

ExecuteReader: Connection property has not been initialized.

Posted on 2007-03-23
10
Medium Priority
?
236 Views
Last Modified: 2008-02-01
Using vb.net 2005 - I just need to run a quick query...and return the results.
I have the query defined in Access (2003), so if it works to just execute that, I'm okay with that route as well...
Here's my code:

Dim strSQL As String = "SELECT EntryDate, UserName, IIf(Decision=True,'gratned','denied') AS Permitted, Amount FROM tblHistory WHERE ShareName=[@ShareName];"
Dim sConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\*****\*****\tsset.mdb;" 'server data masked

Dim con As OleDbConnection = New OleDbConnection(sConStr)
con.Open()
Dim ShareParm As New OleDbParameter
With ShareParm  'I've not used parameters before, so maybe I didn't set this up correctly?
  .ParameterName = "@ShareName"
  .OleDbType = OleDbType.VarChar
  .Size = 50
  .Value = txtShare.Text
End With

Dim cmd As OleDbCommand = New OleDbCommand(strSQL)
cmd.Parameters.Add(ShareParm)

Dim dr As OleDbDataReader = cmd.ExecuteReader  ' <<<  This is where it bombs with the error in the title

While dr.Read
   ....
0
Comment
Question by:sirbounty
[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
  • 7
  • 3
10 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 18779400
Add

cmd.Connection = con

after

Dim cmd As OleDbCommand = New OleDbCommand(strSQL)

Roger
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18779418
Yay!  It's Roger (aka, Mr. Patience)  :^)
Let me give that a shot...thanx.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18779446
I got a ContextSwitchDeadlock (oh my! )
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Author Comment

by:sirbounty
ID: 18779498
Hmm - worked that time (I was stepping before)...but when it gets to the dr.read section, it skips right over, as if it's not 'read' anything...any idea (or does this take us outside of the scope of the original question?)
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18779525
Turn this

"SELECT EntryDate, UserName, IIf(Decision=True,'gratned','denied') AS Permitted, Amount FROM tblHistory WHERE ShareName=[@ShareName];"

into this

"SELECT EntryDate, UserName, IIf(Decision=True,'gratned','denied') AS Permitted, Amount FROM tblHistory WHERE ShareName = ?;"

or even this

"SELECT EntryDate, UserName, IIf(Decision=True,'gratned','denied') AS Permitted, Amount FROM tblHistory WHERE ShareName = ?"

OleDb uses ? rather than names as placeholders and then applies the parameters in the ORDER in which they are referred to rather than using their NAMES.

Roger
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18779551
And is 'gratned' intended to be 'granted'?  Not that that should affect operation ;-)

Roger
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18779588
No it doesn't - and I've flipflopped that numerous times (because in the Access query, it's misspelled...I keep copying from that and then updating it in my code...haha) - but thanx for noticing...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18779607
Hmm - nope, neither work.
Since you've obviously solved the question as stated, I'll open this in a new one...(hoping that you'll help me there as well! :^)
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18779642
http://www.experts-exchange.com/Q_22468189.html if you're interested.
Thanx Roger. :^)
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18779671
<smack> - I was testing this in my form_load...so my txtShare was empty! lol...
Thanx Roger
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
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 …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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