I have a ASP.NET page in C# that calls a stored procedure and returns a small result set, and I'm unable to read the UniqueIdentifer element from that result set. What am I doing wrong?
Steve
Here is the final select statement of my Stored Procedure that contains the value I need the C# routine to work with. The 'UserId' field is defined as a uniqueidentifier in the SQL table.
This is the code from the ASP 'cs' file
Here is the error message that I'm getting
UserId
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: UserId
cSysUserCode = UserReader["UserId"].ToString().Trim();
Steve
Here is the final select statement of my Stored Procedure that contains the value I need the C# routine to work with. The 'UserId' field is defined as a uniqueidentifier in the SQL table.
Code:
SELECT PeopleId, UserId, FirstName, LastName, UserType FROM People
WHERE PeopleId = @UserNumber
This is the code from the ASP 'cs' file
Code:
// Get results from stored procedure
string cSysUserCode;
string cAHFUserId;
int nAHFUserId;
string cFullName;
UserReader = command.ExecuteReader();
if (UserReader.HasRows)
{
while (UserReader.Read())
{
// This first value is not converting to string...
[b]cSysUserCode = UserReader["UserId"].ToString().Trim();
[/b] cAHFUserId = UserReader["PeopleId"].ToString();
nAHFUserId = Convert.ToInt16(cAHFUserId);
cFullName = UserReader["FirstName"].ToString().Trim()
+ " " + UserReader["LastName"].ToString().Trim();
}
}
Here is the error message that I'm getting
UserId
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: UserId
cSysUserCode = UserReader["UserId"].ToString().Trim();