我有如下示例代码:-public List<Announcement_User> announcementUser([FromBody]MyAnnouncementUser value){ MySqlConnection conn = WebApiConfig.conn(); MySqlCommand query = conn.CreateCommand(); query.CommandText = "select a.title,a.description,a.date_created,ua.read,ua.announcement_id,ua.user_announcement_id from announcement a left join user_announcement ua on a.announcement_id = ua.announcement_id where ua.user_id = @user_id"; query.Parameters.AddWithValue("@user_id", value.user_id); var prodWishlist = new List<Announcement_User>(); try { conn.Open(); } catch (MySql.Data.MySqlClient.MySqlException ex) { prodWishlist.Add(new Announcement_User(null, null,null, false, 0, 0, ex.ToString())); } MySqlDataReader fetch_query = query.ExecuteReader(); while (fetch_query.Read()) { prodWishlist.Add(new Announcement_User(fetch_query["title"].ToString(), fetch_query["description"].ToString(), fetch_query["date_created"].ToString(), (bool)fetch_query["read"], fetch_query.GetInt32(4), fetch_query.GetInt32(5), null)); } conn.Close(); return prodWishlist;}我遇到了如下错误:-"Message": "发生错误。","ExceptionMessage": "指定的演员表无效。","ExceptionType": "System.InvalidCastException",现在怀疑是bool导致的错误。我可以知道如何为 bool in(fetch_query.Read()) 编写正确的方法吗?请帮忙。谢谢你。
- 2 回答
- 0 关注
- 229 浏览
添加回答
举报
0/150
提交
取消