-
Sep 3rd, 2015, 02:57 AM
#1
Thread Starter
Member
Saving Datagridview Records if not(already) exists and deleting any other records.
Hi to all,
I have always had this problem where: if I have a datagrid with records like
RecID Name
2 Tom
5 Rich
6 Harry
To Save I will loop through the rows using the sql
IF NOT EXISTS(SELECT * FROM myTable WHERE RecID= dgv.rows(i).cells(0).value say)
BEGIN INSERT the row.(the use INSERT COMMAND)
At the end of the loop I have to delete all records whose RecID are not in the Datagrid.
My Problem is:
How do I create a kind of list of datagrid RecIDs and do something like
DELETE FROM myTable WHERE RecID NOT IN (2,5,6)
Thanks in advance
-
Sep 3rd, 2015, 06:07 AM
#2
Re: Saving Datagridview Records if not(already) exists and deleting any other records
Here's an example of doing it the proper way, using parameters:
http://www.vbforums.com/showthread.p...-SQL-IN-Clause
Given that you're only using your own IDs though, rather than user-entered text, you probably don't really need parameters. As such, you can take out the parameter part of that and just concatenate the actual values into the SQL if you want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|