views:

135

answers:

5
+1  A: 

No you do not need a worry about EOF or using a DataGridView. Just as you can use an ExecuteNonQuery method to insert multiple rows you can also do the same when using DELETE.

Data manipulation statements such as INSERT, UPDATE and DELETE do not generate a result set and hence you would normally use ExecuteNonQuery to run them. All the data manipulation runs in the database server engine.

AnthonyWJones
A: 
DELETE FROM tblSend WHERE id = 5;

This will delete all rows that match the WHERE condition.

I am not sure I understand the relevance of the DataGridView. If it is databound, it will automatically remove the records as well. You only need to issue the delete query once and the rest should happen automatically, assuming you have the databinding correct.

JYelton
A: 

What do you mean by "if they exist"? Compared to what?

To delete multiple records from table 1, you have to make a loop which goes through your table and compare.

Pseudo code:

forach (whatever as whut)
 row = select whatever from table1.

 if (whut == row)
  copy row from table 1 to table 2;
  Delete from table 1 where whut.id == row.id;
Steven
A: 
DELETE FROM tblSend WHERE id = 5;

This is the one solution for deletion a record. If you want to set the identity key to 0 again, use this code

 DBCC CHECKIDENT('tblSend', RESEED, 0);

Then press F5,

Dilse Naaz
A: 

If I understand correctly you need all data from table1 in table2 and then delete table1.

Options

1) It you need it once you could rename table1 to table2 and recreate table1

-- move the records to table 2, ok I assume it does not exist;)
RENAME TABLE table1 TO table2;
-- Create new table1 with same structure as table 2
CREATE TABLE table1 AS SELECT * FROM table2 WHERE 1=2;

2) Do a separate copy and delete assuming you have something like a primary key

-- copy the records
INSERT table2(field1, field2, ...) SELECT field1, field2, ... FROM table1;
-- and delete them 
DELETE FROM table1;

3) Do it using C# but as this seems a database problem to me I would not go that far in pulling all the records to the client and then throwing them back.

Janco