Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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. :)
Posted
Comments
Sergey Alexandrovich Kryukov 25-Jul-14 20:07pm    
Okay, you screwed up some code. But how can we know where and how?
—SA
andy.g10 30-Jul-14 22:23pm    
Hello, Sergey.

I'm writting into my cells with this:

xlWorkSheet.Cells[_lastRow, 4] = clientePropApellidos.Text;
xlWorkSheet.Cells[_lastRow, 6] = clientePropNom.Text;

It works like a charm, my C# code automaticaly starts the Excel file and everything is fine there, but I honestly have no idea on how to add a GUID or something like that and then make my program to compare the values with the Excel Sheet.

Also, I'm using this library "Excel = Microsoft.Office.Interop.Excel;" I tried many and it was the best for me.

Thaks for your answer, Sergey :)

1 solution

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[^]
 
Share this answer
 
v5
Comments
andy.g10 30-Jul-14 22:19pm    
Hello.

Yes, I can already differentiate different rows in the Excel sheet, I left a column for client ID.

I was thinking about adding a GUID to each client, but I honestly have no idea about how to make my program search on the Excel Sheet to compare my data.

I have this problem, and I'm stuck with it, I have searched a lot and tried a lot and I can't get it.

By the way, I write on each cell this way:

xlWorkSheet.Cells[_lastRow, 4] = clientePropApellidos.Text;
xlWorkSheet.Cells[_lastRow, 6] = clientePropNom.Text;

That works pretty well for me.

Thanks for your answer, Peter :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900