R
Robert Brown
Hi All.
I have a routine that checks a SQL Table for all records 3 months
prior to a predetermined date, then I insert them into an Archive DB
then delete those records from the original table.
When I do a "select" for the records, I load them into a dataset, use
an "insert" statement to insert the info into the second table (by a
for next loop and using executenonquery , then a "delete" statement to
remove them.
The way I delete them is "loop" through the rows of the dataset,
create an SQL statement then use ExecuteNonQuery (see code below).
Surely, this is NOT the way to do it as most times, the record count
is around 70000-10000, and it seems to take quiet a while to do (maybe
about 3 records a second).
Could someone advise the most appropriate and speedy way to delete the
items. Remember the records are in a dataset, and I have read
somewhere that you can update/Delete/Insert into SQL using the
Dataset, but not sure of the command.
Any help would be much appreciated.
Thanks,
Robert
<---------------------- Code ----------------------->
Dim iloop as integer
Dim dsorderItems as new dataset
For iloop = 0 To dsOrderItems.Tables("t1").Rows.Count - 1
sSql = "delete tbl_OrderItems where OrderNum = '" &
dsOrderItems.Tables("t1").Rows(iloop).Item("OrderNum") & "'"
updCommand = New SqlCommand(sSql, SQLConn)
updCommand.Connection.Open()
updCommand.ExecuteNonQuery()
updCommand.Connection.Close()
Next
I have a routine that checks a SQL Table for all records 3 months
prior to a predetermined date, then I insert them into an Archive DB
then delete those records from the original table.
When I do a "select" for the records, I load them into a dataset, use
an "insert" statement to insert the info into the second table (by a
for next loop and using executenonquery , then a "delete" statement to
remove them.
The way I delete them is "loop" through the rows of the dataset,
create an SQL statement then use ExecuteNonQuery (see code below).
Surely, this is NOT the way to do it as most times, the record count
is around 70000-10000, and it seems to take quiet a while to do (maybe
about 3 records a second).
Could someone advise the most appropriate and speedy way to delete the
items. Remember the records are in a dataset, and I have read
somewhere that you can update/Delete/Insert into SQL using the
Dataset, but not sure of the command.
Any help would be much appreciated.
Thanks,
Robert
<---------------------- Code ----------------------->
Dim iloop as integer
Dim dsorderItems as new dataset
For iloop = 0 To dsOrderItems.Tables("t1").Rows.Count - 1
sSql = "delete tbl_OrderItems where OrderNum = '" &
dsOrderItems.Tables("t1").Rows(iloop).Item("OrderNum") & "'"
updCommand = New SqlCommand(sSql, SQLConn)
updCommand.Connection.Open()
updCommand.ExecuteNonQuery()
updCommand.Connection.Close()
Next