sirbounty
asked on
ExecuteReader: Connection property has not been initialized.
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.OL EDB.4.0;Da ta 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(SharePa rm)
Dim dr As OleDbDataReader = cmd.ExecuteReader ' <<< This is where it bombs with the error in the title
While dr.Read
....
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
Dim sConStr As String = "Provider=Microsoft.Jet.OL
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(SharePa
Dim dr As OleDbDataReader = cmd.ExecuteReader ' <<< This is where it bombs with the error in the title
While dr.Read
....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got a ContextSwitchDeadlock (oh my! )
ASKER
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?)
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
"SELECT EntryDate, UserName, IIf(Decision=True,'gratned
into this
"SELECT EntryDate, UserName, IIf(Decision=True,'gratned
or even this
"SELECT EntryDate, UserName, IIf(Decision=True,'gratned
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
And is 'gratned' intended to be 'granted'? Not that that should affect operation ;-)
Roger
Roger
ASKER
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...
ASKER
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! :^)
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! :^)
ASKER
https://www.experts-exchange.com/questions/22468189/oleDBDataReader-is-apparently-empty.html if you're interested.
Thanx Roger. :^)
Thanx Roger. :^)
ASKER
<smack> - I was testing this in my form_load...so my txtShare was empty! lol...
Thanx Roger
Thanx Roger
ASKER
Let me give that a shot...thanx.