Updating database

rickb

Member
Joined
Dec 31, 2002
Messages
17
Location
St. Louis, Missouri
I have the code in place to display, in a list box, a list of tables in a database. I also have a button_click event in place to delete a selected table from the list box. What I need to know is how do I delete the selected table from the database? Thanks in advance for any replies.
 
Never mind; I got it.

Dim cmd As OleDbCommand = New OleDbCommand()
OleDbConn.Open()
cmd.Connection = OleDbConn

cmd.CommandText = "DROP TABLE " & lstTables.SelectedItem
cmd.ExecuteNonQuery()
OleDbConn.Close()
lstTables.Items.Remove(lstTables.SelectedItem)

My question was based on the problem I was having with the SQL statement; I kept getting a "Syntax error in DROP TABLE or DROP INDEX" error. The problem, apparently, was the "lstTables.Items.Remove(listTables.SelectedITem)" line came after the "cmd.Connection=OleDbConn" line. I guess the cmd.ExecuteNonQuery() command was trying to delete a table that, according to the listbox, didnt exist.

This may appear as a simple solution to the problem, but I am still relatively new to VB.Net. A valuable lesson learned.
 
Back
Top