从c#在Excel中编写唯一信息 [英] Writing unique information in Excel from c#

查看:66
本文介绍了从c#在Excel中编写唯一信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我正在使用Excel工作簿作为数据库,我的代码在C#WinForms中并且已经在每个Excel列上写入并从字母中过滤文本等。



但我有一个问题,当我双击N次添加按钮时,它会写入N次相同的信息。



我需要我的程序能够在添加之前进行过滤,我的意思是,如果我试图两次添加相同的信息,程序会使信息在我的文本框中可见,怎么会我能做到吗?我在网上尝试了很多东西,但没有一个可以工作。



请帮助我。 :)

解决方案

除非有某种方法来区分Excel工作表中的行,否则你不能这样做。我们可以从关系数据库中借用主键的概念。您将需要一个仅允许每行中唯一值的列。然后检查此列中的任何新数据,以便在单击添加按钮时插入之前检测重复。它的工作方式类似于任何关系数据库表的主键。

参考:什么是主键 [ ^ ]

Hello

I'm using an Excel workbook as database, my code in C# WinForms and already writes on each Excel column and filters the Text from letters, etc.

But I have one problem, when I double click N times "add" button, it writes N times the same information.

I need my program to be able to make someking of filtering before adding, I mean, if I'm trying to add the same information twice the program would make the information visible in my textboxes, how would I be able to do that? I've tried many things on the net, but none of them work.

Please help me. :)

解决方案

You can't unless there is some way to differentiate rows in the excel sheet. We can borrow the concept of primary key from relational database. You will need a column that only allows a unique value in every row. Then check any new data against this column to detect duplication before inserting when the add button is clicked. It works like the primary key of any relational database table.
Refer: What is primary key[^]


这篇关于从c#在Excel中编写唯一信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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