Inserting a variable into the selectparameters of a SQL command

E

evandela

Hi evreyone, I am a newbie but my ASP.net is comming on thanks to you
guys and the countless manuals I have downloaded... ummm... I mean
'bought'

I am having a little bit of an issue though, I am sure it is easy to
sort out - but I cant seem to find any info on it.

I have a variable that I would like to insert into the SQL code... but
cant seem to figure out how to do it... this is what my code looks like
right now... if I replace the ? with a product number the SQL query
works.... but I have a variable called SelectedProductID and I need to
find out how to get that into the SQL query :(


Dim SelectedProductID as Int32 = 4

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
AvaliableColours.SelectCommand = "SELECT colours.colourID as
ALLColourID, colours.colour, avaliableColours.productID,
avaliableColours.colourID FROM colours, avaliableColours WHERE
colours.colourID = avaliableColours.colourID AND
avaliableColours.productID=?"
End Sub

<asp:AccessDataSource ID="AvaliableColours" runat="server"
DataFile="~/App_Data/products.mdb" />

Any ideas ?
 
G

Guest

If SelectedProductID is numeric value then use:
AvaliableColours.SelectCommand = "SELECT colours.colourID as ALLColourID,
colours.colour, avaliableColours.productID, avaliableColours.colourID FROM
colours, avaliableColours WHERE colours.colourID = avaliableColours.colourID
AND avaliableColours.productID= " & SelectedProductID

If it is string value then use:
AvaliableColours.SelectCommand = "SELECT colours.colourID as ALLColourID,
colours.colour, avaliableColours.productID, avaliableColours.colourID FROM
colours, avaliableColours WHERE colours.colourID = avaliableColours.colourID
AND avaliableColours.productID= '" & SelectedProductID & "'"

Hope this helps,
VHD50.
 
G

gella

try this ....it should work

"SELECT colours.colourID as
ALLColourID, colours.colour, avaliableColours.productID,
avaliableColours.colourID FROM colours, avaliableColours WHERE
colours.colourID = avaliableColours.colourID AND
avaliableColours.productID=" & SelectedProductID &" "
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top