Results 1 to 5 of 5

Thread: Database work

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    2

    Database work

    I am creating a project that accesses various databases and am stuck on deleting the database. I am using a Jet connection and I am able to display the database in a data grid view but I have two problems.

    The first is when I click on a certain square and I want to delete this row then how am I able to do this?

    The second is I want to delete the whole database with a click of a button.

    Any help would be appreciated.

    Thanks

    The Squirrel

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

    Re: Database work

    If you want to delete a row in a DataGridView then you press the Delete button, assuming the grid is configured to allow deletions. Check the grid properties and that should be fairly obvious.

    As for deleting the whole database, do you actually mean deleting all the data in the database or deleting the data file itself? Also, what type of database is it? You say that you're using Jet so I'm guessing Access, but the Jet provider supports other data sources too.
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    2

    Re: Database work

    Thanks for replying jmcilhinney.

    Ah I have discovered the delete on the datagridview but it doesn't update the database. I require it to do this.

    Sorry yes I am using access and I want to clear the database of all records rather than deleting the file.

    Thanks again and in advance for any help that you give me.

    The Squirrel

  4. #4
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Re: Database work

    You must call the Update method of the DataAdapter.
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

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

    Re: Database work

    You should probably follow the Database FAQ link in my signature and check out somw of the ADO.NET resources there.

    If you want to delete every record in a table in a database you can simply execute a DELETE statement with no WHERE clause, so every record matches, e.g.
    SQL Code:
    1. DELETE FROM MyTable
    It should be noted though, that that will not reset any AutoNumber columns. In SQL Server there is a TRUNCATE statement that will reset identity columns too. I'm not sure whether Jet SQL has an equivalent but you could check the reference to see.
    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