一对多关系sql怎么办? [英] one to many relationship sql what to do?

查看:80
本文介绍了一对多关系sql怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对多关系的桌子



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





就像我在这种情况下有17张桌子,当我编辑我的表格并且用户向汽车添加一行表我目前正在这样做



i删除汽车表中的所有行然后再次插入因为用户的不确定性不知道哪些行由用户更新所以是还有其他方法吗?



注意用户可以在编辑时添加行...................



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 ...................

推荐答案

您不需要每次都删除和插入..在您从gridview中的表格显示数据时,将datagridview的第一列设置为Visible = False

并用car_id填充该列

并在保存数据时检查
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
If DataGridView1.Item(0, YourRowIndex).Value = "" Then
   'Insert
Else
   'Update
   'Fire your update statement here
End If


这篇关于一对多关系sql怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆