Solved

Moving a select statement from aspx file to .cs file

Posted on 2013-05-15
3
524 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 40

Accepted Solution

by:
Kyle Abrahams earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now