0

I'm doing the following query, and trying to use a code that come from a previous query. But is giving me the following error: The server tag is not well formed.

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:TesteConnectionString %>" SelectCommand="SELECT * FROM [Equipa] where idAssemb=1 and idDept=<%# Eval("idDept") %>"></asp:SqlDataSource>

I'm using C# in Web forms asp.net

Can somebody help me on this?

Adil
  • 146,340
  • 25
  • 209
  • 204

1 Answers1

1

Eval is used in DataBound controls to evaluate a field value in a row from the data source. You are trying to use it inside a Data Source control itself (SQLDataSource in this case). You should use parameterized query by specifying the value of parameter inside SelectParameters tag like this:-

<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
  ConnectionString="<%$ ConnectionStrings:TesteConnectionString %>" 
  SelectCommand="SELECT * FROM [Equipa] where idAssemb=1 AND idDept=@DeptId>
   <SelectParameters>
       <asp:ControlParameter ControlID="lblDeptId" Name="DeptId" 
            PropertyName="Text" Type="Int32" />
  </SelectParameters>
</asp:SqlDataSource>

Please note, here I have shown the example of a control present inside your WebForm. You can specify where the value of DeptId is coming from via Cookie, QueryString, Form, Session etc.

Rahul Singh
  • 21,585
  • 6
  • 41
  • 56
  • @CarlosSantos - You're Welcome. You can accept the answer if it helped you. http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Rahul Singh Feb 01 '16 at 11:23