Most likely you won't find exact code that suits your needs. Instead you need to understand and learn each step for making the program. After all programming isn't about copying.
As said break the problem into smaller pieces. Taken this is SQL Server:
1. Draw the form, add necessary elements to it and give them proper names. Don't use
Textbox1
but names like
LastName
.
2. Create the code for connecting into database and executing the
INSERT
statement. You can for example read through
Properly executing database operations[
^]
3. To return the newly added key value use the
OUTPUT clause[
^]
While creating each piece of the program, take your time, explore and observe the different possibilities how to do things, make slight modifications to see how they affect and always utilize the debugger to understand the behaviour:
Navigating through Code with the Debugger[
^]