Avatar of javierpdx
javierpdx
Flag 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.
.NET ProgrammingC#ASP.NET

Avatar of undefined
Last Comment
javierpdx

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kyle Abrahams

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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?)
javierpdx

ASKER
Got it.  Thanks.  It's working now without the commandtext.

I appreciate the help.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy