Print Page | Close Window

SelectCommand, Variables, & SQL.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=15306
Printed Date: 29 March 2026 at 7:08am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: SelectCommand, Variables, & SQL.
Posted By: davidshq
Subject: SelectCommand, Variables, & SQL.
Date Posted: 31 May 2005 at 2:04pm
Here is a working SQL Statement:
    "Select TOP 5 * from Games"
But I want the 5 to be replaced by a variable. Here is my now non-working code:
    "Select TOP " & Profile.GamesConfig.NumOfGames & " * from Games"
What am I doing wrong?
David.


-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.



Replies:
Posted By: dfrancis
Date Posted: 31 May 2005 at 2:16pm
Make sure Profile.GamesConfig.NumOfGames is a number
 
gamenumber = CINT(Profile.GamesConfig.NumOfGames)
 
"Select TOP " & CINT(Profile.GamesConfig.NumOfGames) & " * from Games"
 
Just taking a stab at it.


Posted By: Mart
Date Posted: 31 May 2005 at 2:22pm
The chances are that Profile.GamesConfig.NumOfGames is an Integer any way... and if not you need to use

"Select TOP " & CInt(Profile.GamesConfig.NumOfGames).ToString() & " * from Games"

What is the actual error that you get?


Posted By: davidshq
Date Posted: 31 May 2005 at 2:38pm
Here is the full SqlDataSource code I am now using:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:gamesConnectionString %>"
SelectCommand="SELECT TOP " & Cint(Profile.GamesConfig.NumofGames).ToString() & " * FROM Game"></asp:SqlDataSource>
And I receive the following message under the design window:
Error Creating Control - SqlDataSource1
The server tag is not well formed.
David.


-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.


Posted By: Mart
Date Posted: 31 May 2005 at 4:21pm
Ah, you can't do that in the designer...

Just remove the SelectCommand ="xx" part from the designer, then in code view just go

SqlDataSource1.SelectCommand = "SELECT TOP " & Cint(Profile.GamesConfig.NumofGames).ToString() & " * FROM Game"

(in Page_Load)


Posted By: davidshq
Date Posted: 01 June 2005 at 9:44am
Mart - What would I do without you? Thanks. It works great now. :-)
David.


-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net