ASP.net InnerException:将记录添加到数据库
已阅读我的教科书,但当我尝试向数据库添加记录时,我仍然遇到捕获内部异常的问题。在我的类中捕获 InnerException 的正确语法是什么?
内心的期望被抛在 db.SaveChanges 上。以下是我的“addReviews.cs”类文件中用于添加记录的代码:
public void addReview(int restId, int timeID, string dateValue, string describe, int cuisineId, int serviceId, int ambianceId, string memberId)
{
REVIEW addReview = new REVIEW();
addReview.REVIEW_DATE = Convert.ToDateTime(dateValue);
addReview.REVIEW_DATE_SUBMITTED = DateTime.Today;
addReview.REVIEW_DESC = describe;
addReview.TIME_ID = timeID;
addReview.REVIEWER_ID = 1;
addReview.FOOD_ID = cuisineId;
addReview.SERVCE_ID = serviceId;
addReview.AMBIENCE_ID = ambianceId;
addReview.REST_ID = restId;
addReview.PRICE_ID = 1;
//Add record to database
db.AddToREVIEWs(addReview);
db.SaveChanges();
}
提前致谢!
Been through my textbook, but I'm still having problems with catching an inner exception as I try to add a record to the database. What is the proper syntax for catching an InnerException in my class?
The inner expection is being thrown on the db.SaveChanges. Here is the code in my 'addReviews.cs' class file to add the record:
public void addReview(int restId, int timeID, string dateValue, string describe, int cuisineId, int serviceId, int ambianceId, string memberId)
{
REVIEW addReview = new REVIEW();
addReview.REVIEW_DATE = Convert.ToDateTime(dateValue);
addReview.REVIEW_DATE_SUBMITTED = DateTime.Today;
addReview.REVIEW_DESC = describe;
addReview.TIME_ID = timeID;
addReview.REVIEWER_ID = 1;
addReview.FOOD_ID = cuisineId;
addReview.SERVCE_ID = serviceId;
addReview.AMBIENCE_ID = ambianceId;
addReview.REST_ID = restId;
addReview.PRICE_ID = 1;
//Add record to database
db.AddToREVIEWs(addReview);
db.SaveChanges();
}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
PS:尝试捕获更具体的异常,在您的情况下,也值得捕获
SqlException
。Try this out:
PS: try to catch more specific exception, in your case it worth to catch
SqlException
as well.