Hi,

I have used oledb connection with sql to populate one of my listbox with data from the database. However, I have to remove. on click of a button. the information from a specific table called 'Salary'. The problem that I am having is that when I tried to remove the 'Salary' table, it is not letting me do so. I says that another table called 'Employees Information' has details from the 'Salary'. How do I remove the 'Salary' table. I don't know if it is possible without removing the other table. If so, how do I do that? Can anyone help me?

Thanks

There are two thing that we need to take care.
1. do we have need to delete table Or
2. We need to delete data

If you want to delete data only then you can use sql command

Delete from salary

and then you can re add data manually or automatically.

Hi Alekhan,

I need to delete from the table called 'Salary' in where there is a column called 'hours'. How do I do that?

Thanks

VB.net will not allow you to delete until you have relationship between Employee Information and Salary, To delete Table you must delete the Relationship between Salary and Emp Info Tables.

Hi Alekhan,

Yes, that is the issue that I am having. I am stuck pretty much there. How do I delete the relationship by using the code rather than doing it manually?

Thanks

can you provide me your sample code and database attached here or u can email me at Alfajarcom@gmail.com

Hi Alekhan,

Here is the sample code:

Dim myConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ nwind.mdb;User Id=admin;Password=;")
Dim myCmd As New OleDbCommand
Dim mySQL As New StringBuilder
Try

myConn.Open()
mySQL.Append("Delete From Products ")

myCmd.Connection = myConn
myCmd.CommandType = CommandType.Text
myCmd.CommandText = mySQL.ToString()

myCmd.ExecuteNonQuery()

myConn.Close()

Catch ex As Exception
MsgBox(ex.Message)
If myConn.State = ConnectionState.Open Then
myConn.Close()
End If
End Try


I am using Northwind sample database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.