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

In project i require to build a screen where i need to edit table from sql server. i have created a WPF project and using datagrid to edit table. but customer is expecting same editing like in management studio (i.e enter on edit mode). i tried to set begedit on current cell changed and tried different events. but facing problems like some times two cells will be in edit mode and some times new line place holder will not come. and many more...

I couldn't see any complete example of insert, update, delete operations with enter on edit mode.

Can some body help me with and example of crud operations and enter on edit mode.



Thanks And Regards
Easwar
Posted

1 solution

Hello Easwar,

I have a solution for you. Just try it out. It may be helpful to you. I hope you don't have any problems with loading tables from database to datagrid. After loading table to datagrid, for example, consider you have loaded employee table from database to your datagrid, after that, you can proceed with editing in datagrid, you can do whatever opration you want to do, and use the following function to save your updated, deleted, newly inserted data to database.

Hope you are using SqlDataAdapter to get table from database. Use this in save function.
SqlCommandBuilder objBuilder = new SqlCommandBuilder(objSqlDataAdapter);//your SqlDataAdapter object used to load table will comes here as argument
objBuilder.GetInsertCommand();
objBuilder.GetDeleteCommand();
objBuilder.GetUpdateCommand();
objAdap.Update(objTable);//your table that you have assigned to datagrid given as objTable

Above code takes care of insert, update, delete operations, you don't need to write code for these operations. And make sure that you have one key column(Primary key) in each table in your database, beacuse which will act as reference key column when Delete operation occurs.
 
Share this answer
 
v2

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