By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,290 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,290 IT Pros & Developers. It's quick & easy.

Parameters it doesnt work (for me)

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
--------------
"Fia" <fi*****@telia.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.