Link to home
Start Free TrialLog in
Avatar of javierpdx
javierpdxFlag for United States of America

asked on

Moving a select statement from aspx file to .cs file

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.
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of javierpdx

ASKER

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?)
Got it.  Thanks.  It's working now without the commandtext.

I appreciate the help.