1

This fix possibly pretty easy. When I copy and paste it works, but my SelectCommand is too long and I need to get it from the code behind.

Aspx file:

<asp:SqlDataSource ID="sds_Dashboard" runat="server" ConnectionString="<%$
                   ConnectionStrings:MyDbConn %>"
                   SelectCommand="<%= SelectCommand.ToString() %>">

Cs file:

public partial class Dashboard : System.Web.UI.Page
{
    public string SelectCommand = "Select * from .....";
}

Error:

Incorrect syntax near '<'.

3
  • 1
    Are you sure it isn't the $ in ConnectionString="<%$? Commented Feb 1, 2013 at 6:35
  • @Despertar If I write my connection string directly to the selectcommand then it works so I didn't think that it is related to $ Commented Feb 1, 2013 at 6:37
  • The '$' is black and not the expected red color. Which is the point I think he was trying to make... Commented Feb 1, 2013 at 6:39

3 Answers 3

1

You can set SelectCommand of SqlDataSource in code-behind's Page_Load instead of aspx file:

sds_Dashboard.SelectCommand = "Select * from .....";
Sign up to request clarification or add additional context in comments.

Comments

0

There maybe a constant newline in your code here:

ConnectionString="<%$ //HERE
                   ConnectionStrings:MyDbConn %>"

. But my concern is a little different, why can't you custom define your select statement in the window that looks like this:

enter image description here

Instead of in the code-behind?

Comments

0

Try to change your ASP.NET code into something like this:

<asp:SqlDataSource ID="sds_Dashboard" runat="server" ConnectionString="<% ConnectionStrings:MyDbConn %>" />

Then from Code Behind, After some If/Else blocks, try this:

sds_Dashboard.SelectCommand = "Select * FROM ...";

It should work fine now.

Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.