Author |
Topic |
krista80
Starting Member
29 Posts |
Posted - 2011-02-04 : 08:46:23
|
Need some help with a where clause in a SQL query. What I am trying to do is post data from a SQL Server 2005 database table to an ASP.NET web form. The table looks like this:ResultsID(Primary Key, Identity, Int)SessionID(varchar(max))FirstNumSet(varchar(max))SecondNumSet(varchar(max))ThirdNumSet(varchar(max))FourthNumSet(varchar(max))FifthNumSet(varchar(max))ResultDate(date)The query in the ASP.NET code looks like this:SelectCommand="SELECT FirstNumSet, SecondNumSet, ThirdNumSet, FourthNumSet, FifthNumSet FROM Results WHERE SessionID = Session.SessionID"I know that without the WHERE the select statement works, so definately has to do with the where. Can anyone help? I am trying to put the information into a GridView on the webform, using an SqlDataSource. I am using SessionID so as to only post the numbers that go with the current user's SessionID. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-02-04 : 08:52:05
|
SelectCommand = "SELECT FirstNumSet, SecondNumSet, ThirdNumSet, FourthNumSet, FifthNumSet FROM Results WHERE SessionID = " & CHR(39) & Session("SessionID") & CHR(39) N 56°04'39.26"E 12°55'05.63" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-04 : 09:08:33
|
Also make use of a stored procedure and pass values using an command objectMadhivananFailing to plan is Planning to fail |
 |
|
krista80
Starting Member
29 Posts |
Posted - 2011-02-04 : 09:31:26
|
Okay. Tried that. I still don't see anything on the web form. Maybe I need to rewrite the whole select statement? Or maybe I am missing something from my GridView or SqlDataSource? The GridView code looks like this:<asp:GridView ID="grdResults" runat="server" DataSourceID="srcResults" AutoGenerateColumns="false" AllowPaging="true" > <Columns> <asp:BoundField DataField="FirstNumSet" HeaderText="FirstNumSet" SortExpression="FirstNumSet" /> <asp:BoundField DataField="SecondNumSet" HeaderText="SecondNumSet" SortExpression="SecondNumSet" /> <asp:BoundField DataField="ThirdNumSet" HeaderText="ThirdNumSet" SortExpression="ThirdNumSet" /> <asp:BoundField DataField="FourthNumSet" HeaderText="FourthNumSet" SortExpression="FourthNumSet" /> <asp:BoundField DataField="FifthNumSet" HeaderText="FifthNumSet" SortExpression="FifthNumSet" /> </Columns></asp:GridView>SqlDataSource code looks like this:<asp:SqlDataSource ID="srcResults" runat="server" ConnectionString="<%$ ConnectionStrings:TestDatabaseConnectionString %>" SelectCommand="SELECT FirstNumSet, SecondNumSet, ThirdNumSet, FourthNumSet, FifthNumSet FROM Results WHERE SessionOD = & CHR(39) & Session(SessionID) & CHR(39)"> <asp:SelectParameters> <asp:SessionParameter Name="SessionID" SessionField="SessionID" Type="String" /> </asp:SelectParameters></asp:SqlDataSource> |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-04 : 09:50:55
|
WHERE SessionID became WHERE SessionOD, maybe just a typo?JimEveryday I learn something that somebody else already knew |
 |
|
krista80
Starting Member
29 Posts |
Posted - 2011-02-04 : 09:56:15
|
Yes sorry. That is a typo on here. It's SessionID in the actual code. |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-04 : 10:25:02
|
Could you print out what SelectCommand actually looks like before it gets executed?JimFull Disclosure -- I know zip about ASPEveryday I learn something that somebody else already knew |
 |
|
krista80
Starting Member
29 Posts |
Posted - 2011-02-04 : 11:06:22
|
SelectCommand="SELECT [FirstNumSet], [SecondNumSet], [ThirdNumSet], [FourthNumSet], [FifthNumSet] FROM [Results] WHERE ([SessionID] = @SessionID)">That is how it looks now in my program. |
 |
|
krista80
Starting Member
29 Posts |
Posted - 2011-02-10 : 13:03:21
|
Thanks. I figured it out. |
 |
|
|