更新sql server 2008 r2中的记录时出现问题 [英] Problem in updating records in sql server 2008 r2

查看:81
本文介绍了更新sql server 2008 r2中的记录时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i使用c#和sql server 2008作为数据库的asp.net web应用程序。



i有一个转发器,我有复选框和化学名称。

它将保存那些被选中的,直到这里它的确定。



但是,在更新中,我遇到了问题。

如果用户选择了1,2,3并保存。而不是1,3,4用户选择1,2,3。

现在他想要更新它。



更新时,如果记录不存在,它将插入。

但是,如何删除未被选中的记录,

bcoz更新时没有选择...

(插入/更新只有在选中/检查时才会触发)



有人可以帮助我。





谢谢

Hi guys,

i have asp.net web application using c# & sql server 2008 as Database.

i have a repeater, where i have checkbox and chemical name.
it will save those which are selected, till here its ok.

but, in updating, i'm getting a problem.
if user selected 1, 2, 3 and save. instead of 1,3,4 the user selected 1,2,3.
now he want to update it.

while updating, if the record does not exists it will insert.
but, how to remove record which were not selected,
bcoz it was not selected while updating...
(insertion/update will trigger only if its selected/checked)

can anyone please help me.


thanks

推荐答案

感谢全能,我明白了。



i有一个隐藏的字段,我在那里存储化学记录ID。



以及任何方式,我有一个复选框。



i已经放了一个循环,



if(hdn.value!= null && checkbox.checked == false)

{

删除记录;

}





n



感谢所有人回复...
Thanks to Almighty, i got it.

i have taken one hidden field, where i'm storing chemical record id.

and any how, i have a check box.

i have put one loop,

if(hdn.value != null && checkbox.checked == false)
{
delete the record;
}


n

thanks to all of u guys for reply...


快速而肮脏的方式... < b / b


当你点击时,你删除了过去的每一个选择,而不是你写的所选项目。



但更好应该是将所选择的值与有效值进行比较,而不是:

- 如果选择和数据库中都存在一个值,则保留原样

- 如果某个值不存在在数据库中创建它

- 如果选择中不存在值,则删除它
quick and dirty way...

when you click, you delete every past selection and than you write your selected items.

but better should be to compare selected with the esistent values, than :
- if a value exists both in selection and "database" leave as is
- if a value does not exist in "database" create it
- if a value does not exist in selection delete it


这篇关于更新sql server 2008 r2中的记录时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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