For a Gridview:
I am trying to use a stored procedure for the first time in a SQLDataSource for the UpdateCommand:
I really wouldn't use a SqlDataSource
. It will be much easier if you make the call to the database in the code-behind (or a better yet in a Data Access Layer).
If you use a SqlDataSource
the stored procedure call will only be available on that page. Every time you want to make that same call you will have to copy and paste the SqlDataSource
or make a UserControl
out of it.
The following example uses the Entity Framework to connect to the database and retrieve records:
public List GetAllRecordsByUserName(string credentials)
{
List recordList;
using (CustomEntities context = new CustomEntities())
{
IQueryable recordQuery = from records in context.Records
where records.UserName == credentials
select records;
recordList = recordQuery.ToList();
}
return recordList;
}