Click here to Skip to main content
15,900,480 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guys ,

how can i add only one record to database.

For example , when i write myname to txtName then i click the button , it will save to the nameField...after i write another time my name it will overwrite the same field..how can i do it ? in database İdentity increases 1,2,3,4,5.. , i just want only one place.
Posted
Comments
bbirajdar 14-Sep-12 8:46am    
Use UPDATE query instead of INSERT

Just delete the table before you insert data into it.

SQL
Delete from [Your Table Name]

INSERT INTO [Your Table Name]
(
   Name
)
VALUES
(
   @Name
)
 
Share this answer
 
As aspnet_regiis already suggested, we call it UPDATE[^].
 
Share this answer
 
Hi,

In such scenario you should use some KeyValue pair in the database. Instead of creating number of columns for the information, create only two column. one for Key and another with it's Value.

By default your table have some default value. And each time you can update the information from the table.

You should use this scenario only when you do not have any option to save the information other then database.

--------------------
key      | value
--------------------
username | abc
otherinfo| infovalue
nextinfo | nextvalue
---------------------


Many people may not accept this methodology but this is my personal opinion

Thanks
 
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