The specified cast not valid occurs when I try to get the fieldreader to datatype int.
_userid
is of int
type in database
var _fieldReader = sqlCmd.ExecuteReader();
while (_fieldReader.Read())
{
_userId = _fieldReader.GetInt16(0);
}
sqlCon.Close();
Can anyone please help me with the issue?
If user_id is int type in your database it match with a 32bits integer. Use GetInt32()
instead :
_userId = _fieldReader.GetInt32(0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.