Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I work in c# 2015 windows form

I have excel file 2007 name book 1 and sheet inside it name sheet 1

sheet 1 have two column

UserID

UserName

I need when insert new record from windows form c#

to check if the value of User Name found before show to client message tell him that Username exist before

UserID UserName

1 michel

2 marten

IF user enter in textbox value of marten then click button insert

give me message that this name exist before

using c# windows form

How to do that by c# if possible

What I have tried:

How to prevent adding item to excel 2007 if it found before c#
Posted
Updated 4-Feb-17 11:12am
Comments
[no name] 28-Jan-17 20:02pm    
If your query returns a result, then the information already exists.
Richard MacCutchan 29-Jan-17 3:57am    
Obviously you need to look up the name first to see if it already exists in the worksheet.
CHill60 30-Jan-17 8:13am    
Where is the code you have already tried and where are you stuck?

1 solution

So you should do a Vlookup on the column with the userID in it (I assume you're using SQL to check), then return the next column information, if it returns information, then that UserID is already in use. No need to show the information, just notify the windows form to try again.

As you are using a UserID, I'm assuming that you are trying to create a list of users for access validation. If you are trying to validate users, you need to rethink the columns and the way it's used.

Give us some more information on why you are doing this, because it may be possible to help you find a better method.
 
Share this answer
 

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