Adding variable to SQL Server query VB.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm attempting to add a variable to a WHERE clause in a SQL query datasource.
I want to add the variable in my page_load statement.

The datasource looks like this:
<asp:SqlDataSource
ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:STest %>"
SelectCommand="SELECT dbo.SAdminAdd.CID,
dbo.SAdminAdd.Server, dbo.SAdminAdd.CreatedDate, dbo.SAddStatus.notes,
dbo.SAddStatus.updateTime, dbo.SStatusNames.fullname FROM dbo.SAdminAdd INNER
JOIN dbo.SAddStatus ON dbo.SAdminAdd.CID = dbo.SAddStatus.CID INNER JOIN
dbo.SStatusNames ON dbo.SAddStatus.status = dbo.SStatusNames.status WHERE
(dbo.SAdminAdd.UID = <variable here>)">
</asp:SqlDataSource>

Any help is greatly appreciated.

I apologize if I have selected the wrong newsgroup.
 
Oh, this is the right newsgroup...
I would investigate how to program ADO.NET Parameter objects.
Basically, you need to define a SqlCommand with the CommandText set to your
query but with "@UIDWanted" (or somesuch) in place of "<variable here>".
Next, add a SqlParameter to the Command.Parameters collection (Add comes to
mind) and set the Value property of this parameter just before execution...

It's all explained in detail in at least three of my books.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top