hi, i want to delete data in database from textbox. after i execute my program.there was error saying that oledbexeption was unhandelled and Syntax error in FROM clause.

can you help me..

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim data As String
            Dim objCmd As New OleDbCommand
            data = "delete FROM schedule ([subjek], [hari], [masa], [kelas], [tempat],[pensyarah]) "
            data = data & "VALUES('" & (Me.TextBox1.Text) & "', '" & (Me.TextBox2.Text) & "','" & (Me.TextBox3.Text) & "','" & (Me.TextBox4.Text) & "','" & (Me.TextBox5.Text) & "','" & (Me.TextBox6.Text) & "' );"
            Dim Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Asus\Documents\schedule table.accdb")

            objCmd = New OleDbCommand(data, Con)


            MessageBox.Show("You have successfully delete the data.")


Edited by Reverend Jim: title typo

5 Years
Discussion Span
Last Post by G_Waddell

Just try with
Delete From "TableName" Where "Some Condition" : if you want to delete data based on some conditions.
Delete From "TableName"



You have not supplied a WHERE clause in your SQL and it looks like you have mixed up the syntax between an INSERT statement and the DELETE Statement.

With Insert Statements, you are creating new records so you pass in the table columns and the values.

With DELETE, SELECT and UPDATE statements you either apply to the whole table or you add a WHERE clause to apply to a subset of the data. i.e. If I run DELETE FROM MyUserTable - I have deleted every record from MyUserTable if I run DELETE FROM MyUserTable WHERE (UserID = 5) then I have only deleted the records where the UserID column has a value of 5.

If you carry out a SQL Delete command , you are deleting the record so you do not specify the columns.

If however, you want to "delete" the values in certain record(s) for specific columns then you would apply a SQL Update command i.e. UPDATE MyUserTable SET Title='' WHERE (UserID =5) would "blank" the title column of any record where the UserID column equals 5.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.