473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataGridView: validating rows for duplicate

Hi,

I have a DataGridView bounded to a database table. I'm trying to validate a row entered by a user with the RowValidating event. What i want to do is check if the user entered a value already in the database. The problem is that when the RowValidating event is fired, the IsNewRow property is already set to false, but the value is not in the DataTable yet.

For example, if the user adds a new row in the database, I check in my DataTable if the value is already there. If so, I show an error message. But if the user doesn't create a new row and renames one with an already existing value, the error message will pop because the value is already there.

That's why I tried to use the IsNewRow property, to know if we're dealing with a new row or just an edit. But the value is always false, event when I'm adding a new row.

So, how can I know that the user is add a new row? And is there a better way to check for duplicate?

Thank you!
Nov 10 '08 #1
1 4373
dip_developer
648 Expert 512MB
i can just give you a logical way.....because i dont know how you are managing your insert /updates...........

take a flag(a variable)...to hold the edit/insert status.......whenever user creats a new row in the grid(by clicking a button or so) set the flag value to 1 or "insert" or as you want......otherwise the flag value will be 0 or "update" or as you want............

Dim flag As String=""

whenever user creates a new row set
flag="insert"

now you have to play in the SQL Query by checking the flag............

If flag="insert" Then
'check for the duplicate record
else
'check for the duplicate record leaving the current record which is being edited
End If
Nov 12 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Arvind | last post by:
Hi I edit a cell in a DataGridView, and then would move to another cell in the DataGridView using mouse. Then the DataGridView as of now does scroll down to the last visited cell. But when I try...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: Rich | last post by:
Hello, Following an example at http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker) on binding a dataRelation to a Datagridview for sqlClient, I was able to view rows...
3
by: steve | last post by:
Hi All How can I get the datagridview to redraw after changing the rowtemplate.height at runtime ( it is databound to a datatable) I have tried datagridview1.refresh etc to no avail (The row...
2
by: Rich | last post by:
Hello, I am just checking if there is a property or technique for displaying or retrieving from a dataTable the top 1 row(s) for rows containing duplicate keys (IDs). I have to pull data from a...
1
by: nwmotogeek | last post by:
Is it possible to span multiple rows with a single column? For example I may want to associate two items with a persons name and want that name spanned accross both rows (each item) . Is this...
0
by: =?Utf-8?B?aW1yYW4uYQ==?= | last post by:
Hi all, I am having a problem with inserting rows in to my datagridview control. The datagridview is bound to a bindingsource with a filter set. If i try and add a row to the datagridview while...
1
by: jay parzych | last post by:
I have many tables that are 'lookup' tables and want to provide a way for users to Add/Update rows to them. I will present the data in a datagridview, using a collection of objects connected to...
0
by: =?Utf-8?B?S3VtYXIuQS5QLlA=?= | last post by:
I edit a cell in a DataGridView, and then would move to another cell in the DataGridView using mouse. Then the DataGridView as of now does scroll down to the last visited cell. But when I try to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.