PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Adding variable to SQL Server query VB.NET
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Adding variable to SQL Server query VB.NET
![]() |
Adding variable to SQL Server query VB.NET |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

