PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Adding variable to SQL Server query VB.NET

Reply

Adding variable to SQL Server query VB.NET

 
Thread Tools Rate Thread
Old 14-09-2006, 08:21 PM   #1
=?Utf-8?B?VCBNY0RvbmFsZA==?=
Guest
 
Posts: n/a
Default Adding variable to SQL Server query VB.NET


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.
  Reply With Quote
Old 14-09-2006, 10:53 PM   #2
William \(Bill\) Vaughn
Guest
 
Posts: n/a
Default Re: Adding variable to SQL Server query VB.NET

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.
__________________________________

"T McDonald" <TMcDonald@discussions.microsoft.com> wrote in message
news:4EAB541D-9C22-47E2-97E6-66EEDE508022@microsoft.com...
> 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.



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off