Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > what is the best practice ??????
 

what is the best practice ??????

I m going to design a newwindows bussiness aaplication Please tell me what is best technique& standard approach

for "INSERT" , "VIEW" , "DELETE" AND "UPDATE" operations in winformsn how can use it with classes in vb.net.

thanks in advance.
Ejaz Maqbool  Thursday, December 25, 2008 1:46 PM

Hi Ejaz,

Based on my understanding, you'd like to create a WinForm application that retrieves data from DB and also inserts, updates ordeletes records and then saves the changes back to DB. If I'm off base, please feel free to let me know.

As for the user inferface, I suggest you add a DataGridView control andButtons for "add", "modify", "delete" and "view" operations on the main form.
1. When starting, the application retrieves data form DB and shows all records in the DataGridView.

2. To add a new record, click the "Add" button. A "insert record" dialog pops up. Fill the fieldsand click "Ok" button in this dialog and the new record is saved into DB. Then the fields in the "insert record" dialog reset blank and you can add another record in this dialog. Click "Cancel" button to close this dialog.

3. To modify a record, select one row in the DataGridView and click the "Modify" button. A "edit record" dialog pops up showing the detailed information of the selected record. Change the values you want and click the "Ok" in this dialog button to save the changes to DB. Click "Cancel" button to close this dialog.

4. To delete a record, select one row in the DataGridView and click the "Delete" button. A messge box shows asking whether you really want to delete this record. Answer "Yes" to delete it and this record is also deleted from DB.

5. To view the detailed information of a record, select one row in the DataGridView and click the "View" button or double click a row in the DataGridView. A "detail information" dialog pops up showing the detailed information of this record.

As for the internal implementation, you can create a typed DataSet at design-time accordingto the table interested in DB.
1. Create an instance of the typed DataSet on the main form and bind the DataGridView to it.

2. When the main form loads, use a SqlDataAdapter to retrieve data from DB and fill the data in the DataSet instance.

3.When the "Add" button is clicked, pass the DataSet instance and the SqlDataAdapter tothe "insert record" dialog. When the Ok button is clicked,create a DataRow and add it to the DataSet instance and then call SqlDataAdapter.Update method to save the new record to DB. Call theAcceptChanges method on the DataSet instance.

4. When the"Modify" button is clicked, pass the SqlDataAdapter and the selected DataRow to the "edit record" dialog. When the Ok button is clicked, callthe SqlDataAdapter.Updatemethod to save changes to DB and then call the AcceptChanges method on the DataSet instance.

5. When the "Delete" button is clicked, call the DataRow.Delete method and then call SqlDataAdapter.Update method to delete this record from DB. Call the AcceptChanges method on the DataSet instance.

6. When the "View" button is clicked, pass the selected row to the "detail information" dialog.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu

Linda Liu  Friday, December 26, 2008 8:27 AM

Hi Ejaz,

Based on my understanding, you'd like to create a WinForm application that retrieves data from DB and also inserts, updates ordeletes records and then saves the changes back to DB. If I'm off base, please feel free to let me know.

As for the user inferface, I suggest you add a DataGridView control andButtons for "add", "modify", "delete" and "view" operations on the main form.
1. When starting, the application retrieves data form DB and shows all records in the DataGridView.

2. To add a new record, click the "Add" button. A "insert record" dialog pops up. Fill the fieldsand click "Ok" button in this dialog and the new record is saved into DB. Then the fields in the "insert record" dialog reset blank and you can add another record in this dialog. Click "Cancel" button to close this dialog.

3. To modify a record, select one row in the DataGridView and click the "Modify" button. A "edit record" dialog pops up showing the detailed information of the selected record. Change the values you want and click the "Ok" in this dialog button to save the changes to DB. Click "Cancel" button to close this dialog.

4. To delete a record, select one row in the DataGridView and click the "Delete" button. A messge box shows asking whether you really want to delete this record. Answer "Yes" to delete it and this record is also deleted from DB.

5. To view the detailed information of a record, select one row in the DataGridView and click the "View" button or double click a row in the DataGridView. A "detail information" dialog pops up showing the detailed information of this record.

As for the internal implementation, you can create a typed DataSet at design-time accordingto the table interested in DB.
1. Create an instance of the typed DataSet on the main form and bind the DataGridView to it.

2. When the main form loads, use a SqlDataAdapter to retrieve data from DB and fill the data in the DataSet instance.

3.When the "Add" button is clicked, pass the DataSet instance and the SqlDataAdapter tothe "insert record" dialog. When the Ok button is clicked,create a DataRow and add it to the DataSet instance and then call SqlDataAdapter.Update method to save the new record to DB. Call theAcceptChanges method on the DataSet instance.

4. When the"Modify" button is clicked, pass the SqlDataAdapter and the selected DataRow to the "edit record" dialog. When the Ok button is clicked, callthe SqlDataAdapter.Updatemethod to save changes to DB and then call the AcceptChanges method on the DataSet instance.

5. When the "Delete" button is clicked, call the DataRow.Delete method and then call SqlDataAdapter.Update method to delete this record from DB. Call the AcceptChanges method on the DataSet instance.

6. When the "View" button is clicked, pass the selected row to the "detail information" dialog.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu

Linda Liu  Friday, December 26, 2008 8:27 AM

You can use google to search for other answers

Custom Search

More Threads

• CRM 3.0 sample senario
• I download a TaskVision Source File,but I connot find the web service source part or the db definition part
• Print method
• Is it possible to use the PhotoListView outside of this application?
• programming code that lets you draw a polygon using visual basic?
• help!!!
• How to get text from ListView Control using SendMessage API
• task notification service?
• using XPandercontrol
• Username and password