Thanks to all that replied..
Juan and Cor have given me some real insight into how to perform the
operations. I was only putting it into a dataset because I thought
that might be the fastest, but I knew there was a better way.
I have tried out Juan's code and it certainly kills the timing of my
code.
Thank you all for the fast replies once again..
Robert
"Juan Romero" <(E-Mail Removed)> wrote in message news:<ej7Yv$(E-Mail Removed)>...
> Robert,
>
> My dear friend, the answer is right in front of your eyes....
>
> Why execute a query to delete every single record when you can execute a
> query to delete ALL Records older than 3 months?, for example:
> DELETE FROM Table1 WHERE YourFieldDate <='00/00/00'
>
> To begin with, why go through all the records generating insert statements
> when you could move them all in one shot with a single query?, for example:
>
> select * into Table2 from Table1 WHERE YourFieldDate <= '00/00/00'
>
> Good luck,
>
> Juan.
>
> "Robert Brown" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
|