Problem using parameters in query

G

Guest

All,
I am using the Visual studio development tool, but I am having a problem
figuring out how to populate a parameter.

my commandtext is this:
cmdDeal.commandText = select * from tbl where deal_date = ?

on page load:
dtmDate = '08/15/05'

dim dealParam as new sqlParameter("@DealDate", dtmDate)
cmdDeal.Parameters.add(dealParam)
dealConnection.Open()
cmdDate.executeReader()



If I check what the commandtext is the sqlstatement has not changed from the
above statement.

Also when I execute the query (lets assume that it is right). Is there some
code that I need to put in before I executeReader..

thank
samantha
 
L

Lucas Tam

my commandtext is this:
cmdDeal.commandText = select * from tbl where deal_date = ?

on page load:
dtmDate = '08/15/05'

dim dealParam as new sqlParameter("@DealDate", dtmDate)
cmdDeal.Parameters.add(dealParam)
dealConnection.Open()
cmdDate.executeReader()

I believe the proper syntax is:

cmdDeal.commandText = select * from tbl where deal_date = @DealDate
 
G

Guest

Ok well I changed to your now, but now if I display the commandtext i get
seleect .. from .. where deal_date = @DealDate

So what else am I missing?
sam
 
G

Guest

The .NET Framework Data Provider for SQL Server does not support the question
mark (?) placeholder for passing parameters to a SQL Statement or a stored
procedure called by a Command of CommandType.Text. In this case, named
parameters must be used.

HTH

Elton Wang
 
G

Guest

Forget my last reply
I have modified code to be
commandtext = select .. from .. where deal_date = @DealDate

then in code:
CmdDeal.Parameters("@DealDate").Value = dtmDate

Why does my command text stil say select .. from .. where deal_date =
@DealDate

Should it not say select * from .. where deal_date = '8/15/05'???

I am so lost
sam
 
L

Lucas Tam

Why does my command text stil say select .. from .. where deal_date =
@DealDate

Should it not say select * from .. where deal_date = '8/15/05'???

Your commandtext will remain select .. from .. where deal_date = @DealDate
but the actual query return will include the parameters.

The SQL client doesn't replace your commandtext... It does that in the
background.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top