如何在数据库中添加值 [英] how to add values in the database

查看:64
本文介绍了如何在数据库中添加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表格中,我有5个字段,在这些字段中,这些字段是

1.questionId
2.questionUserId
3.SurveyId
4.answer
5.answerId

保存记录时,我正在传递"answer"字段和调查"字段作为我的操作方法的参数.我的答案参数是用字符串分隔我的半列的形式.并通过执行for循环,我试图将值保存到数据库中.

我要保存的是,对于添加新记录,在for循环中,除"answer"之外,所有记录值都相同.和"answerId"这是自动递增.在保存时,第一次保存新记录,但在下一次迭代时,它已抛出DuplicateKeyUnhandledByUserCode和标识为"1850137295-2-1-2-11"的"DataModel.question_answer"实例

In my table I have 5 fields,In those fields,Those are

1.questionId
2.questionUserId
3.SurveyId
4.answer
5.answerId

while I was saving records,I am passing "answer" field and "survey" field as a parameter to my action method. My answer parameter is in the form of string separated my semicolumn.I am splitting this one using "semicolumn" and by executing the for loop I am trying to save values into the database.

How I have to save is that,For adding new record,In the for loop all record values are same except "answer" and "answerId" which is auto incrementing. while I am saving,For the first time of execution new record is saving but for next iteration,It is throwing DuplicateKeyUnhandledByUserCode and Instance of ''DataModel.question_answer'' with identity ''1850137295-2-1-2-11'' already exists in the cache of the object scope.

推荐答案

在循环中创建表类型的新对象
Create a new Object of The table type in the loop


这篇关于如何在数据库中添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆