Connecting Tech Pros Worldwide Forums | Help | Site Map

Inserting a variable into the selectparameters of a SQL command

evandela@bigpond.net.au
Guest
 
Posts: n/a
#1: Mar 22 '06
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 ?


VHD50
Guest
 
Posts: n/a
#2: Mar 22 '06

re: Inserting a variable into the selectparameters of a SQL command


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.


"evandela@bigpond.net.au" wrote:
[color=blue]
> 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 ?
>
>[/color]
gella
Guest
 
Posts: n/a
#3: Mar 29 '06

re: Inserting a variable into the selectparameters of a SQL command


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 &" "

Closed Thread