Recent: Trying to find lawn mower part- Power Devil PDG4037R?

Mend Microsoft Application Development

Mend Software, Application Development
Find out how to mend it for free.

Ask Question
Mend Software, Application Development
Click here to mend Microsoft application development

Mend > Application Development

Mend Software, Application Development

How can I delete all rows in a data table?

I have a VB.Net question. I am having trouble deleting all rows in a data table. I am using this code........

Dim ConnStr As String = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + System.Windows.Forms.Application.StartupPath + "\Clip Counter.mdb"
Dim DT As New DataTable()
Dim SQLStr As String = "SELECT * FROM [Clips_Data]"
Dim DA As New OleDb.OleDbDataAdapter(SQLStr, ConnStr)
Dim CommandBuilder As New OleDb.OleDbCommandBuilder(DA)
DA.Fill(DT)
DT.Rows.Clear()
DA.Update(DT)

........After the clear command all the table's rows are deleted, but it seems as though the change is not saved. What am I doing wrong?

P.
February 2004
You basically need to change your SQLStr. Use the lines below instead of your example.

Dim ConnStr As String = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + System.Windows.Forms.Application.StartupPath + "\Clip Counter.mdb"
Dim DT As New DataTable()
Dim SQLStr As String = "DELETE * FROM [Clips_Data]"
Dim DA As New OleDb.OleDbDataAdapter(SQLStr, ConnStr)
Dim CommandBuilder As New OleDb.OleDbCommandBuilder(DA)
DA.Fill(DT)
DA.Update(DT)
DA.Dispose()

Andrew Croft
February 2004
Mend Software, Application Development
Click here to mend Microsoft application development

How to mend ...

Find out how to mend just about anything howtomendit.com for free repair help, information and advice.
Mend Software, Application Development
Click here to mend Microsoft application development