Results 1 to 4 of 4

Thread: edit, add, delete data in datagridview

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    44

    edit, add, delete data in datagridview

    i have connected my sdf database to vb.net and program is capable to show the database in the datagridview. but what i want is when i change the data in the datagridview and click onto update button,changes i made should be saved in database so when i execute the application again i should be able to see the updated database in the datagridview.
    guide me to add data as well as to delete data too
    pls help me !!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: edit, add, delete data in datagridview

    how have you connected your sdf database?

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    44

    Re: edit, add, delete data in datagridview

    i dont know how to connect the sdf database to a datatable using binding source.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: edit, add, delete data in datagridview

    Quote Originally Posted by bea19_ventura View Post
    i dont know how to connect the sdf database to a datatable using binding source.
    That's no surprise, because that is not possible. You connect to the database and retrieve data into the DataTable, which is then bound to the BindingSource, which is then bound to the UI. What .paul. is asking is basically how you set up the application to retrieve the data in the first place. If you have a DataTable and a BindingSource and you don't know how they work then I think that 's fairly safe to assume that you used the Data Source Wizard to generated a typed DataSet and you then dragged a table from the Data Sources window onto your form. Doing so would add several controls and components to your form as well as a little code.

    You should start by having a look at that code, specifically the Load event handler. You should see there that the Fill method of a table adapter is called, which queries the database and fills the DataTable with the result set. That's how you retrieve the data in the first place.

    You may actually already have code to save the data too. Is there a call to the UpdateAll method of a table adapter manager? If so then that's what does the saving. It might be in the Click event handler of the Save button of your BindingNavigator. If not then you can easily add save code. You'll probably want to handle the Click event of the Save button but you can put the code wherever is appropriate. You can call UpdateAll on the table adapter manager but, if you're only using one DataTable, you don't need to update all tables. Simply copy the Fill line from the form's Load event handler and change the Call to Update instead of Fill. That's it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width