Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Moving a select statement from aspx file to .cs file

Posted on 2013-05-15
3
Medium Priority
?
552 Views
Last Modified: 2013-05-16
Hello,
I'm using c#, .net for my application and connecting to SQL 2012.

I'm having a hard time finding information on how to move this SQLDataSource select statement to the code code behind C# file and referencing it in my aspx page.
This is the reference in my aspx file.  How do I move the select statement to my .cs file?
<asp:SqlDataSource ID="SqlDS" runat="server" 
 ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
SelectCommand="SELECT S.IsActive, S.Title, S.AllowTransfer, S.GuestFee 
FROM Sessions S WHERE (IsActive = 'True') AND (AllowTransfer = 'True')">
                    </asp:SqlDataSource>

Open in new window

Thanks for looking at this.
0
Comment
Question by:javierpdx
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 39169772
SqlDs.SelectCommand.Commandtext = "SELECT S.IsActive, S.Title, S.AllowTransfer, S.GuestFee
FROM Sessions S WHERE (IsActive = 'True') AND (AllowTransfer = 'True')";
0
 

Author Comment

by:javierpdx
ID: 39169793
Thanks.  Am I missing a namespace?
I'm trying this in the CS file but am getting this error:

Error      16      'string' does not contain a definition for 'CommandText' and no extension method 'CommandText' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
0
 

Author Closing Comment

by:javierpdx
ID: 39169863
Got it.  Thanks.  It's working now without the commandtext.

I appreciate the help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question