Hi all I just want to add some functionality in my project. I simply need that when a user enters some details then based on some specific column values if the value entered by user already exists in the database then message should be displayed. if i use primary key then an exception is thrown by SQLException class. I want to check it by myself through coding whether the values entered by user already exists or not.
Thanx in advance

Recommended Answers

All 8 Replies

Then you would need to run a query to see if the details existed ..

LizR is correct. Run a query on your columns to check if it exists, from the database side, you can also add a unique constraint on those columns to ensure that a sqlexception will be thrown if you try to do a insert on an already existing record with the specified columns.

You could be adding a huge time overhead if you do, especially if you dont have sufficient indexes

thanx for replying dickersonka and LiZr
I m doing it by adding primary key to my table and by using DataRowCollection's Find method. But the problem is that my primary key consists of 2 columns and find method takes only 1 parameter. Can i do it by using Stored Procedures. If yes then how because i have never user Sps in C#

You could make a primary key that is the concatination of both fields together, this would be the normal way to do it

How can I cancatinate it ? i mean to say how i pass my primary key to find method which is composed of 2 columns

Um, well if your primary key is Field1+field2

when you do your test, pass Field1value + field2value so its 1 string.

it Didnt work at all But i have got the solution from somewhere else.
anyways thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.