Afternoon all,
I load a number of records into a datatable. I am trying to find out if there is a simple way to remove all the records in my sql table that are in my datatable without having to loop through the datatable and remove 1 record at a time.
Basically, what happens is.. Data is loaded into a datatable and then extracted to a csv file. I therefore no longer require the data in the SQL table that is related to the datatable.
I then do some data manipulation so that the data can be extracted into the correct formats etc....Code:Public Function LoadDatatable(_iSQL As String) As DataTable Try Dim _Datatable As New DataTable Using dCon As _SQLConnection = New _SQLConnection(Configuration.ConnectionString) Using dbCmd As New SqlClient.SqlCommand(_iSQL, dCon.Connection) Using da = New SqlClient.SqlDataAdapter(dbCmd) da.Fill(_Datatable) End Using End Using End Using Return _Datatable Catch ex As Exception MessageBox.Show(ex.Message, "Load Datatable", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Nothing End Try End Function
I could just use a Delete from tableX, but there are likely to be new records created since I loaded the orignal data into the datatable and I don't want to loose these records.
So is it possible to delete the records from my SQL table that match my datatable. I have a unique field called 'id'
Cheers
Dan




Reply With Quote