2

Problem:

Exception Details: System.Data.EntitySqlException: The query syntax is not valid. Near term '<', line 8, column 16.

Code Behind:

    protected void Page_Load(object sender, EventArgs e)
    {

        int Id = 3;

        Page.DataBind();
    }

project.aspx.cs

<asp:EntityDataSource ID="ProjectEntityDataSource" runat="server" ConnectionString="name=DBEntities" DefaultContainerName="DBEntities" EnableFlattening="False" EntitySetName="projects" Select="it.[Id], it.[ClientId], it.[Name], it.[Description]"
    Where="it.ClientId = <%# Id %> " >
</asp:EntityDataSource>

What i have tried: ASP.NET databinding / getting variables from codebehind

I know it's too easy but i'm not able to figure out where the problem really is why i'm not able to bind the code behind data.Thanks!

3 Answers 3

2

You can take help of the following example In your case

protected void Page_Load(object sender, EventArgs e)
{
     ProjectEntityDataSource.WhereParameters["Username"].DefaultValue ="3";
     Page.DataBind();
}

aspx

<asp:EntityDataSource ID="ProjectEntityDataSource" runat="server"
     ConnectionString="name=DBEntities" DefaultContainerName="DBEntities" 
     EnableFlattening="False" EntitySetName="projects" Select="it.[Id], it.[ClientId], 
     it.[Name], it.[Description]" Where="it.ClientId = @Username">
      <WhereParameters>
        <asp:Parameter Name="Username" Type="String" />
    </WhereParameters>
</asp:EntityDataSource>
Sign up to request clarification or add additional context in comments.

Comments

2
<asp:EntityDataSource ID="ProjectEntityDataSource" runat="server" 
    ConnectionString="name=DBEntities" DefaultContainerName="DBEntities" 
    EnableFlattening="False" EnableInsert="True" EnableUpdate="True"      
     EntitySetName="projects" Where="it.ClientId= @Id"  >
    <WhereParameters>
        <asp:QueryStringParameter Name="Id" Type="Int32" QueryStringField="Id" />
    </WhereParameters>
</asp:EntityDataSource>

Try this code.

Comments

1

change like this.....it will work i think...

 Where='<%#"it.ClientId =" + Id.ToString %> ' 

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.