Solved

Moving a select statement from aspx file to .cs file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

24 Experts available now in Live!

Get 1:1 Help Now