Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

I am about to developing a program which is stucked at starting only

Problem : When a user enter some text and click save that should be checked with database whether it is same or not and say Duplicate entry if same, else save to the database

ThnQ
Posted
Comments
[no name] 18-Aug-12 8:48am    
"Problem : "... exactly how is that a "problem"? That is a requirement statement and not a problem or a question. You would benefit by reading http://www.codeproject.com/Articles/64628/Code-Project-Quick-Answers-FAQ paying particular attention to item #4

In my opinion you should utilize the capabilities of the database to enforce the integrity of the data.

The easiest way is perhaps to define a unique constraint on the table. This constraint would ensure that no duplicate rows exist in the table. If a duplicate is trying to be added an exception is thrown which you can then catch in your application.

To learn more about unique constraint, see: http://msdn.microsoft.com/en-us/library/ms191166(v=sql.105).aspx[^]
 
Share this answer
 
Comments
srinu2008 19-Aug-12 8:05am    
Hai, Thnxs for the solution, actually i got a foxpro code about this, that i want to convert in C#
************************************************************************
procedure save_clas_det

if(empty(tcur_clas))

do mesg_wind with 'Incomplete Details . Please Check......'

return

endif


decl temp_arr[1]

if(told_or_new = 1)

sele 5
seek class_arr[tclass_no,2]

trec_no = recno()


temp_arr = 0

select count(*) from &tcl_det_file ;
where name = tcur_clas .and. recno() # trec_no ;
into array temp_arr


if(temp_arr[1] > 0)

do mesg_wind with 'Duplicate Entry . Please Check......'

return

endif

else

temp_arr = 0

select count(*) from &tcl_det_file ;
where name = tcur_clas ;
into array temp_arr


if(temp_arr[1] > 0)

do mesg_wind with 'Duplicate Entry . Please Check......'

return

endif


sele 5
append blank


temp_arr = 0

select max(class) from &tcl_det_file ;
into array temp_arr

repl class with temp_arr[1] + 1

endif

repl name with tcur_clas

if(told_or_new = 1)

if(tcur_clas # substr(class_arr[tclass_no,1],3))

class_arr[tclass_no,1] = space(2) + tcur_clas

show gets

endif

else

do get_cl_det with .f.

tcur_clas = space(tclas_name_len)

show gets

endif

do mesg_wind with 'Class Details Saved......'

******************************************************
It is the piece of code which i want to convert in C# plz let me know, ThnQ
Wendelius 19-Aug-12 8:26am    
As said, I really don't recommend to do the check using the code. There are several possible problems you may encounter in a multi-user environment. In my opinion using a constraint would be the preferred way!
Espen Harlinn 19-Aug-12 8:37am    
Good reply :-D
Wendelius 21-Aug-12 1:01am    
Thanks :)
Hi,

You can write your logic in Stored procedure.

Please check this article :Insert, Update, Search and Delete (CRUD operation) using ASP.Net and MySQL[^]

You have not tag which database you are using.Anyway Here is some code for stored procedure checking. i leave rest on you,

SQL
CREATE PROCEDURE `InsertCountry`(
IN     _CountryName                       varchar(200),
OUT    _ReturnValue                       int
)
BEGIN
 
DECLARE IsCountryExist int(5);
--check if country already exist in database. 
SELECT COUNT(NM_COUNTRY_ID) INTO IsCountryExist FROM
       TBL_COUNTRYMASTER WHERE VC_COUNTRY_NAME = _CountryName;
 
START TRANSACTION;
-- insert record only if duplicate country is not in database.
IF IsCountryExist = 0 THEN
   INSERT INTO TBL_COUNTRYMASTER(VC_COUNTRY_NAME)
          VALUES (_CountryName);
 
END IF;
 
SELECT LAST_INSERT_ID() INTO _ReturnValue;
 
COMMIT;
END   


Hope you got answer from my solution.

Thanks
-Amit Gajjar
 
Share this answer
 
Comments
srinu2008 19-Aug-12 8:05am    
Hai, Thnxs for the solution, actually i got a foxpro code about this, that i want to convert in C#
************************************************************************
procedure save_clas_det

if(empty(tcur_clas))

do mesg_wind with 'Incomplete Details . Please Check......'

return

endif


decl temp_arr[1]

if(told_or_new = 1)

sele 5
seek class_arr[tclass_no,2]

trec_no = recno()


temp_arr = 0

select count(*) from &tcl_det_file ;
where name = tcur_clas .and. recno() # trec_no ;
into array temp_arr


if(temp_arr[1] > 0)

do mesg_wind with 'Duplicate Entry . Please Check......'

return

endif

else

temp_arr = 0

select count(*) from &tcl_det_file ;
where name = tcur_clas ;
into array temp_arr


if(temp_arr[1] > 0)

do mesg_wind with 'Duplicate Entry . Please Check......'

return

endif


sele 5
append blank


temp_arr = 0

select max(class) from &tcl_det_file ;
into array temp_arr

repl class with temp_arr[1] + 1

endif

repl name with tcur_clas

if(told_or_new = 1)

if(tcur_clas # substr(class_arr[tclass_no,1],3))

class_arr[tclass_no,1] = space(2) + tcur_clas

show gets

endif

else

do get_cl_det with .f.

tcur_clas = space(tclas_name_len)

show gets

endif

do mesg_wind with 'Class Details Saved......'

******************************************************
It is the piece of code which i want to convert in C# plz let me know, ThnQ
AmitGajjar 20-Aug-12 0:04am    
but why can't you write your own code C#?
srinu2008 20-Aug-12 0:31am    
I am beginner to C# and i don't know how to code in C#, thats why i am seeking help, plz let me know, ThnQ
AmitGajjar 20-Aug-12 0:33am    
i know dear, thats why i have given you an article for beginner. you go though once and download demo and learn from there. i know it will be hard for you to start but once you will be families, you will love it.
srinu2008 20-Aug-12 0:36am    
ok, i will go through, meanwhile if you have knowledge in that above code to convert into C#, please let me know, and can i have your mail id so that i keep on posting doubts so that i can get quick reply and also gains much experience too, Plz accept my request, ThnQ
Lets try with EmployeeDetails, and you are trying to INSERT new/existing EmpID.

SQL
INSERT INTO dbo.EmployeeDetails(EmpID)
SELECT '123456'
WHERE NOT EXISTS (SELECT EmpID FROM dbo.EmployeeDetails WHERE EmpID = '123456')


Here 123456 will get into this table only if 123456 does not exist.

Thanks,

Kuthuparakkal
 
Share this answer
 
v4
Comments
srinu2008 19-Aug-12 8:05am    
Hai, Thnxs for the solution, actually i got a foxpro code about this, that i want to convert in C#
************************************************************************
procedure save_clas_det

if(empty(tcur_clas))

do mesg_wind with 'Incomplete Details . Please Check......'

return

endif


decl temp_arr[1]

if(told_or_new = 1)

sele 5
seek class_arr[tclass_no,2]

trec_no = recno()


temp_arr = 0

select count(*) from &tcl_det_file ;
where name = tcur_clas .and. recno() # trec_no ;
into array temp_arr


if(temp_arr[1] > 0)

do mesg_wind with 'Duplicate Entry . Please Check......'

return

endif

else

temp_arr = 0

select count(*) from &tcl_det_file ;
where name = tcur_clas ;
into array temp_arr


if(temp_arr[1] > 0)

do mesg_wind with 'Duplicate Entry . Please Check......'

return

endif


sele 5
append blank


temp_arr = 0

select max(class) from &tcl_det_file ;
into array temp_arr

repl class with temp_arr[1] + 1

endif

repl name with tcur_clas

if(told_or_new = 1)

if(tcur_clas # substr(class_arr[tclass_no,1],3))

class_arr[tclass_no,1] = space(2) + tcur_clas

show gets

endif

else

do get_cl_det with .f.

tcur_clas = space(tclas_name_len)

show gets

endif

do mesg_wind with 'Class Details Saved......'

******************************************************
It is the piece of code which i want to convert in C# plz let me know, ThnQ

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