Sorting Data.
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=15384
Printed Date: 29 March 2026 at 3:12am Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Sorting Data.
Posted By: davidshq
Subject: Sorting Data.
Date Posted: 06 June 2005 at 12:11pm
I bet you never expected me to post another question again, right? haha. Okay, here is what I have:
A GridView that displays 10 Games from the tblGames in the Games db.
Here is what I need:
A GridView that displays 10 Games from the tblGames in the Games
db if these Games haven't been played within the last 30 days (which is
stored in the Games db in the tblLastPlayed).
Here is my current (and non-working or I wouldn't be posting this) code:
Dim varUserName As String = Profile.UserName.ToString
Dim varDate As Date = Date.Now
varDate.AddDays(-30)
SqlDataSource1.SelectCommand = "SELECT TOP " &
CInt(Profile.GamesConfig.NumofGames).ToString() & " ID, Title,
Popularity, Type, [Last Played] FROM GAME WHERE '" & varUserName
& "' <> LastPlayed.uID AND LastPlayed.LastPlayedDate > '"
& varDate & "'"
My current problem appears to be that LastPlayed.uID and
LastPlayed.LastPlayedDate are not bound and cannot be bound. Any help
would be appreciated.
David.
------------- - http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.
|
Replies:
Posted By: Mart
Date Posted: 06 June 2005 at 12:15pm
|
What error do you get? Or what do you want to do that you don't know how to?
|
Posted By: davidshq
Date Posted: 06 June 2005 at 12:45pm
Well, I think I have figured out most of it. Basically, my problem at
this point is that the SQL statement doesn't appear capable of
comparing two strings to each other using the <> operators. Here
is my new code:
SqlDataSource1.SelectCommand = "SELECT TOP " &
CInt(Profile.GamesConfig.NumofGames).ToString() & " ID, Title,
Popularity, Type, [Last Played] FROM GAME JOIN LastPlayed ON ('" &
varUserName & "' <> LastPlayed.uID) AND
(LastPlayed.LastPlayedDate > '" & varDate & "')"
I get an error that "The data types varchar and text are incompatible in the not equal to operator."
varUserName is a String and LastPlayed.uID is defined in SQLServer as Text.
------------- - http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.
|
Posted By: davidshq
Date Posted: 06 June 2005 at 1:51pm
I've updated the code once again. This code doesn't throw any errors but doesn't give me any results either:
SqlDataSource1.SelectCommand = "SELECT TOP " &
CInt(Profile.GamesConfig.NumofGames).ToString() & " Game.ID, Title,
Popularity, Type, [Last Played] FROM GAME JOIN LastPlayed ON ('" &
varUserName & "' NOT LIKE LastPlayed.uID)"
What this is supposed to do is show all of the games except for those
where there is an entry in the database with the users username, but
instead of just removing one or two entries for some reason it is not
showing any entries.
David.
------------- - http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.
|
Posted By: davidshq
Date Posted: 06 June 2005 at 3:39pm
Got it all figured out now. Here is the final code:
Dim varNumofGames As String = CInt(Profile.GamesConfig.NumofGames).ToString()
Dim varUserName As String = Profile.UserName.ToString
Dim varDate As Date = Date.Now
varDate.AddDays(-30)
SqlDataSource1.SelectCommand = "SELECT * FROM Game G LEFT OUTER JOIN
LastPlayed LP ON G.ID = LP.gID WHERE (LP.gID IS NULL) OR
(LP.LastPlayedDate > '" & varDate & "') AND (LP.uID LIKE '"
& varUserName & "')"
------------- - http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.
|
|