8 Replies - 349 Views - Last Post: 14 March 2019 - 07:17 PM Rate Topic: -----

#1 geos59   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 87
  • Joined: 30-August 15

Clear all data in Access from a VB button.

Posted 10 March 2019 - 04:29 PM

As the title says, how do I clear all data in Access by using a button in VB.NET?
Is This A Good Question/Topic? 0
  • +

Replies To: Clear all data in Access from a VB button.

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: Clear all data in Access from a VB button.

Posted 10 March 2019 - 04:34 PM

What have you tried or looked into?

SQL has a DELETE and TRUNCATE options available.
Was This Post Helpful? 0
  • +
  • -

#3 geos59   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 87
  • Joined: 30-August 15

Re: Clear all data in Access from a VB button.

Posted 11 March 2019 - 01:28 PM

View Postmodi123_1, on 10 March 2019 - 04:34 PM, said:

What have you tried or looked into?

SQL has a DELETE and TRUNCATE options available.


I looked at both - it seems the DELETE SQL command is what I need, I just don't know how to implement it.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: Clear all data in Access from a VB button.

Posted 11 March 2019 - 01:38 PM

Button event calls a function that uses the basic SQL adapter.. using a well formatted DELETE on your table.
.
https://www.dreaminc...-command-setup/
Was This Post Helpful? 0
  • +
  • -

#5 geos59   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 87
  • Joined: 30-August 15

Re: Clear all data in Access from a VB button.

Posted 12 March 2019 - 03:14 PM

View Postmodi123_1, on 11 March 2019 - 01:38 PM, said:

Button event calls a function that uses the basic SQL adapter.. using a well formatted DELETE on your table.
.
https://www.dreaminc...-command-setup/


I do appreciate your fast responses, but I don't really understand the snippet as how it relates to delete in SQL.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: Clear all data in Access from a VB button.

Posted 12 March 2019 - 04:12 PM

The snippet shows the basic components to connect to a database and interact with it using a SQL statement,
Was This Post Helpful? 0
  • +
  • -

#7 geos59   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 87
  • Joined: 30-August 15

Re: Clear all data in Access from a VB button.

Posted 14 March 2019 - 05:17 PM

View Postmodi123_1, on 12 March 2019 - 04:12 PM, said:

The snippet shows the basic components to connect to a database and interact with it using a SQL statement,


I have created a VB program that already accepts data, here's the gist of it:

 Dim cnn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\REDACTEDINFO\StudentDatabase.accdb; Persist Security Info = True")

            cnn.Open()

            Dim cmm As New OleDbCommand("insert into insertdata values ('" + firstName.Text + "', '" + lastName.Text + "','" + MajorClasses.Text + "','" + RoomNumber.Text + "','" + bannerID.Text + "')", cnn)

            cmm.ExecuteNonQuery()
            cnn.Close()
            MsgBox("Data Successful")


Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: Clear all data in Access from a VB button.

Posted 14 March 2019 - 06:17 PM

Ok?
Was This Post Helpful? 0
  • +
  • -

#9 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 201
  • View blog
  • Posts: 1,125
  • Joined: 05-December 13

Re: Clear all data in Access from a VB button.

Posted 14 March 2019 - 07:17 PM

You say you want to clear all in the database but yet you are inserting data in your command... hmm quite the reverse effect this will have but ok. And if you are inserting data too, use parameters.

Dim cmm As New OleDbCommand("insert into insertdata values

What is so hard about creating a stored procedure CommandType.StoredProcedure :: https://www.develope...-NET-Part-2.htm

Or using "Delete From TableName" - table name being the name of your table?

Preferably some here might advocate "TRUNCATE TABLE TableName" overall.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1