I deduce the data from a DB by means of GridView.

SelectCommand= "SELECT Products.Image, Products.Name, Products.Description, Products.Price, Cart.Amount, Cart.ClientId FROM (Cart INNER JOIN Products ON Cart.ProductId = Products.id)"; 

It is necessary now to display only those records where

 //ключ текущего юзера, именно так я и записывал в таблицу Cart Cart.ClientId = Membership.GetUser().ProviderUserKey.ToString(); 

How to do it?

  • The question is not quite clear to be honest. Have you tried to use the WHERE query? - Sergey Neykovich
  • When registering, the system is assigned a key (user ID) by the system. A user adding a product to the basket transfers his ID to the table of the basket. On the basket page you need to display only the product added by the user. - LEgXr

1 answer 1

You most likely need something like this:

 SqlDataSource1.SelectParameters.Add("ClientId", Membership.GetUser().ProviderUserKey.ToString()); SqlDataSource1.SelectCommand = " SELECT Products.Image, Products.Name, Products.Description, Products.Price, Cart.Amount, Cart.ClientId FROM (Cart INNER JOIN Products ON Cart.ProductId = Products.id WHERE Cart.ClientId = @ClientId"; 

Or

 <asp:SqlDataSource ... SelectCommand = "SELECT Products.Image, Products.Name, Products.Description, Products.Price, Cart.Amount, Cart.ClientId FROM (Cart INNER JOIN Products ON Cart.ProductId = Products.id WHERE Cart.ClientId = @ClientId"> <SelectParameters> <asp:DelegateParameter Name="ClientId"... </SelectParameters> 

Other examples can be found here.