I tried to look this up but no other question really fit. I have a web page where I will be showing analytics. One stat is total amount of users, where i am trying to take the total amount of rows in my user table in a sql database. I had thought the Id would be an int but it appears it is varchar(128). I will include the error and the code. Thank you!!
An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code
public static string GetUserSum(string rConnStr)
{
string UserCount = "";
using (SqlConnection conn = new SqlConnection(rConnStr))
{
const string sqlText = @"
SELECT COUNT(Id)
FROM AspNetUsers
";
using (SqlCommand cmd = new SqlCommand(sqlText, conn))
{
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
bool result = sdr.Read();
if (result)
{
UserCount = DBUtils.GetValue<string>(sdr["Id"]); //it breaks right here
}
}
}
}
return UserCount;
}