.net - How to pass variable to SelectCommand of SqlDataSource? -


I want to pass the variable from the code behind the SelectCommand of SQLDataSource?

I do not want to use the built-in parameter type (such as the control operator, query stringpameter, etc.)

Do I need to pass a viable?

The following example does not work

  & lt; ASP: SQLDataSource ID = "SqlDataSource1" runat = "server" ConnectionString = "& $; ConnectionStrings: itematConnectionString% & gt; SelectCommand =" items.name, items.id from items.id on items.inid = Join users_items.id users_items (users_items.user_id = @userId) by users_items.date DESC order "& gt; & Lt; SelectParameters & gt; & Lt; Asp: parameter defaults = "lt;% = userId%" & gt; Name = "user id" dbippe = "guides" /> & Lt; / SelectParameters & gt;  

You can always do the following in the code:

  SqlDataSource1.SelectParameters.Add ("@ userId", userId);       ; ASP: SQLDataSource ID = "SqlDataSource1" runat = "Server" ConnectionString = "& lt;% $ ConnectionStrings: itematConnectionString% & gt; & Gt;  

Then do the following in the code:

  SqlDataSource1.SelectParameters.Add ("userId", userId.ToString ()); SqlDataSource1.SelectCommand = "Select Items. Join items INNER with names, items, users_items ON items.id = users_items.id WHERE (users_items.user_id = @userId) ORDER BY users_items.date DESC"  

This works for me, also works:

  & asp: SqlDataSource id = "SqlDataSource1" runat = "server" connection string = "& lt;% $ ConnectionStringings: itematConnectionString%> Select "SelectCommand =" items.name, items.id from items.id at intervals.id = users_items.id Where (users_items.user_id = @userId) users_items.date include users_items ordered by DESC Be there "& gt; & Lt; / ASP: SQLDataSource & gt; SqlDataSource1.SelectParameters.Add ("userid", DbType.Guid, userId.ToString ());  

Comments