I’m getting an exception thrown at reader = cmd.ExecuteReader(); when I debug.
CS0266: Cannot implicitly convert type ‘System.IAsyncResult’ to ‘System.Data.SqlClient.SqlDataReader’.
This is a custom MembershipProvider derived from the MSDN sample membership provider (http://msdn.microsoft.com/en-us/library/6tc47t75.aspx) with the username value calling the Email database field rather than a separate Username entry, and the connection was changed from an Odbc to a SQL connection.
public override MembershipUser GetUser(string username, bool userIsOnline)
{
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT UserID, Email, PasswordQuestion," +
" Comment, IsApproved, IsLockedOut, CreationDate, LastLoginDate," +
" LastActivityDate, LastPasswordChangedDate, LastLockedOutDate" +
" FROM Users WHERE Email = ? AND ApplicationName = ?", conn);
cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 128).Value = username;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 255).Value = m_ApplicationName;
MembershipUser u = null;
SqlDataReader reader = null;
try
{
conn.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
u = GetUserFromReader(reader);
if (userIsOnline)
{
SqlCommand updateCmd = new SqlCommand("UPDATE Users " +
"SET LastActivityDate = ? " +
"WHERE Email = ? AND Applicationname = ?", conn);
updateCmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime).Value = DateTime.Now;
updateCmd.Parameters.Add("@Email", SqlDbType.VarChar, 255).Value = username;
updateCmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = m_ApplicationName;
updateCmd.ExecuteNonQuery();
}
}
}
have you tried specify parameter name inside the sqlcommand? the question mark seems strange to me