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

I'd like to know if there's a general practice for inserting (new) records into a DataSet through databound controls.

The scenario is the following: I have a dataGirdView that displays a list of the records and some textboxes bound to the same dataset that display each field separately.

I can edit a record (using the textboxes) and then call dataSet.AcceptChanges(), however, adding a new row to the dataset is a different story. After I create the row I can't position my dataset to it, therefore I can't use the textboxes to populate the fields with data.

Maybe my problem is that I'm trying to approach this "the Delphi way". Any help is much appreciated!

Thank you all,
blizzard
Posted

I NEVER use any of that 'accept changes' crap. I write a proper data layer, and call it to update, insert or delete records. You can't data bind a textbox, as far as I know, although you can create edit/insert templates. In any case, if the template lets me create inline editing or inserting, I'd still expect to write my own code to call a data layer I control to do the insert. Then, you just rebind the grid to the data source and your insertion will be there.
 
Share this answer
 
I agree with CG, you need to understand and use a Data Access Layer (DAL), it is fundamental to controlling you development.

I would also add that you should look at NOT editing in a list control. I always pop a dialog for any CRUD operations and never edit within a list control. This gives you complete control of the data, you can use binding in the dialog, manage any defaults and insure the data is written to the database. Then close the dialog and and reload the list.
 
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