在gridview中插入唯一数据 [英] Insert unique data in gridview

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

问题描述

大家好,

我的程序包含显示在gridview中的数据.只有一列.我需要数据唯一显示,这意味着在网格视图中不允许重复.有人可以帮助我吗?

这是我的代码:

Hi everyone,

my program contains data which displayed in gridview.There''s only one column. Ive need the data uniquely display which means no duplication allowed in the gridview. Anyone can help me?

here is my code:

private void displaystring id)
      {

                  dataGridView1.Rows.Add(id);

      }



请帮助我....



Please help me....

推荐答案

您可以在各个级别处理重复操作:
1.用户界面级别-使用javascript检查,在输入新的或更新的旧数据时,需要唯一的列的值没有重复

2.业务逻辑级别-检查要更新/插入的值是否重复.循环遍历所有值,并根据其返回true或false.相应地执行更新/插入

3.数据库-为要避免重复的字段设置唯一约束.如果发生这种情况,将不允许插入它,并且可以相应地捕获和处理特定于它的错误.
You can handle the duplication at various levels:
1. UI level - Check using javascript that the value of the column that needs to be unique is not duplicating when entered new or updated old

2. Business logic level - check the value being updated/inserted for duplication. Loop through all the values and return true or false based on it. Accordingly execute the updation/insertion

3. Database - set a unique constraint to the field that you are avoiding to be duplicate. If it happens, it wont allow to be inserted and an error specific to it can be caught and treated accordingly.


这篇关于在gridview中插入唯一数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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