Click here to Skip to main content
14,882,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have table with one to many relationships

lodge_id int auto increament
name nvarchar(50)
active bit

another table
car_id int
lodge_id int fk to first table
car_use active


like that i have 17 tables in this case when i edit my form and the user add one row to car table i am currently doing this way

i am deleting all the rows from car table and then inserting once again because of uncertainty of user dont know which rows updated by user so is there any other ways?

note that user can add rows at edit time ...................
Posted
Updated 8-Jul-13 1:53am
v3
Comments
Mukesh Ghosh 8-Jul-13 7:54am
   
Not clear to me. Can you tell what exactly you want to do?
Basmeh Awad 8-Jul-13 7:55am
   
which control you are using on your form??
DatagridView??
Dholakiya Ankit 8-Jul-13 7:57am
   
yes using gridview control
Dholakiya Ankit 8-Jul-13 7:56am
   
yes i am using gridview control
StM0n 8-Jul-13 7:59am
   
I'm not quite sure, if I get a grip on your question... but it seems, that your data model is a little bit mixed up if you have to delete the whole content of a table.
Dholakiya Ankit 8-Jul-13 8:02am
   
explained in details-------------

one table taxlodgment and another car etc
in car table multiple rows are there for one row of tax lodgment

so when user edit cars he can add / edit / update and currently i am deleting all rows from table cars and then inserting again so is there any other ways?

1 solution

you don't need to delete and insert every time..in the begining when you are displaying data from table in your gridview set the first column of your datagridview to Visible=False
and fill that column with car_id
and at the time of saving data check
VB
If DataGridView1.Item(0, YourRowIndex).Value = "" Then
   'Insert
Else
   'Update
   'Fire your update statement here
End If
   
Comments
Dholakiya Ankit 8-Jul-13 8:21am
   
no user can update already inserted data
Basmeh Awad 8-Jul-13 8:23am
   
ya so whats the problem..the new data will get insert and the already inserted data will got updated
Dholakiya Ankit 8-Jul-13 8:28am
   
ok so this will be a best way to do that right?
so i am taking it as solution
Basmeh Awad 8-Jul-13 8:30am
   
your choice:-)
Dholakiya Ankit 8-Jul-13 8:34am
   
ok (:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900