Parameters it doesnt work (for me)

F

Fia

Hi
I have tried the code below to ask a question from an Access database, but I
don't get any records wich I know I should.

sökaOrdCom = New OleDbCommand("Select * from kött where köttid Like
@KöttID", DBConn)
sökaParam.ParameterName = "@KöttID"
sökaParam.DbType = DbType.String
sökaParam.SourceColumn = "Köttid"
sökaParam.Value = "'" & PubStr & "*'"
sökaOrdCom.Parameters.Add(sökaParam)
Trace.WriteLine(sökaOrdCom.CommandText)
sökaOrdRead = sökaOrdCom.ExecuteReader

Do While sökaOrdRead.Read
recCount += 1 'This code never happens
Loop
sökaOrdRead.Close()

I have also tried the code below but I this isn't working either.
sökaOrdCom = New OleDbCommand("Select * from kött where köttid Like
@KöttID", DBConn)
sökaOrdCom.Parameters.Add("@KöttID","'" & PubStr & "*'")
Trace.WriteLine(sökaOrdCom.CommandText)
sökaOrdRead = sökaOrdCom.ExecuteReader

Do While sökaOrdRead.Read
recCount += 1 'This code never happens
Loop
sökaOrdRead.Close()

I thought that when you added the parameter the CommandText should look like
this if PubStr = 'b'
"Select * from kött where köttid Like 'b*'", but it doesnt it still looks
the same.
I have no idea why this isn't working. I hope some of you have.

I miss the property RecordCount, isn't there any property like that in
Visual Basic .NET or do you have to run a while loop to get the recordcount.

PLEASE HELP!!

Fia
 
K

Ken Tucker [MVP]

Hi,

The * is not a wild card character anymore use the % sign instead.
Do not pass the ' into a parameter. This is what the parameters value
should be.

sökaParam.Value = PubStr & "%"


Ken
--------------
Hi
I have tried the code below to ask a question from an Access database, but I
don't get any records wich I know I should.

sökaOrdCom = New OleDbCommand("Select * from kött where köttid Like
@KöttID", DBConn)
sökaParam.ParameterName = "@KöttID"
sökaParam.DbType = DbType.String
sökaParam.SourceColumn = "Köttid"
sökaParam.Value = "'" & PubStr & "*'"
sökaOrdCom.Parameters.Add(sökaParam)
Trace.WriteLine(sökaOrdCom.CommandText)
sökaOrdRead = sökaOrdCom.ExecuteReader

Do While sökaOrdRead.Read
recCount += 1 'This code never happens
Loop
sökaOrdRead.Close()

I have also tried the code below but I this isn't working either.
sökaOrdCom = New OleDbCommand("Select * from kött where köttid Like
@KöttID", DBConn)
sökaOrdCom.Parameters.Add("@KöttID","'" & PubStr & "*'")
Trace.WriteLine(sökaOrdCom.CommandText)
sökaOrdRead = sökaOrdCom.ExecuteReader

Do While sökaOrdRead.Read
recCount += 1 'This code never happens
Loop
sökaOrdRead.Close()

I thought that when you added the parameter the CommandText should look like
this if PubStr = 'b'
"Select * from kött where köttid Like 'b*'", but it doesnt it still looks
the same.
I have no idea why this isn't working. I hope some of you have.

I miss the property RecordCount, isn't there any property like that in
Visual Basic .NET or do you have to run a while loop to get the recordcount.

PLEASE HELP!!

Fia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Oledb???? 1
Parameter it doesn't work (for me) II 5

Top