I had a login page. once user successfuly logged in, they can view and manage their profile/information. This would be done by retrieving data from database and display on a
If you already have the parameter listed in your SqlDataSource, then simply point to it and change it's value ...
e.Command.Parameters["@UserId"].Value = currentUserId;
You do not need to create a parameter, unless you have not listed it back in your ASP page.
Create a new SqlParameter and add it to the collection.
SqlParameter param = new SqlParameter("@UserId", currentUserId);
e.Command.Parameters.Add(param);
Try the following:
DbParameter param = e.Command.CreateParameter();
param.ParameterName = "@UserId";
param.Value = currentUserId;
e.Command.Parameters.Add(param);
I didn't test this though
You must add the parameter with
e.Command.Parameters.AddWithValue("@UserId", currentUserId);
Once you have added it you could access it through the indexer as in your example.
If you are working with the System.Data.Common
namespace, the AddWithValue
method is not available. You will have to do something like
var param = e.Command.CreateParameter("@UserId", currentUserId);
e.Command.Parameters.Add(param);
This is a little bit more complicated but has the advantage that you do not have to implicitly create a parameter of a specific type like SqlParamter
or OleDbParameter
.