问题描述
有一个Windows窗体,这个窗体有一个
1.用户可以附加多个文件(任何类型的文件),这些附加的文件必须转到表A并且必须保存为Attachment1,attachments2, - (我们可以将不同扩展名的附件数量限制为5)分别针对相同的ID)
示例:如果表A中的ID为1234。我必须在不同的列中获取附件,例如
附件1 ID - 1234
附件2 ID -1234在不同栏中
这些文件必须显示在数据网格视图中
我能够以正确的方式获得一个文件,我甚至可以在数据网格视图中看到文件的内容。
问题:
我无法为辅助表中附加的所有文件获取相同的ID,因为主表ID列是唯一标识符。
II需要编写一个sql查询来获取具有相同ID的不同附件这样
附件1 ID - 1234
附件2 ID - 1234
预先谢谢
我尝试过:
我可以附加一个文件来查看,因为它在表1中没有重复值,但在附加多个文件时不起作用
There is a windows form and this form has an
1. where a user can attach multiple files (any type of file) and these files attached has to go to the Table A and have to be saved as Attachment1, attachments2,--(we can limit the number of attachments to 5 with different extensions) in different columns respectively for the same ID)
example: if ID from Table A is 1234. I have to get the attachments in different columns like the
Attachment 1 ID – 1234
Attachment 2 ID -1234 in different columns
And these files has to be displayed in the data grid view
I am able to get one file working the correct way as I wanted I can even see the content of the files in the data grid view.
Problem:
I am not able to get the same ID for all the files attached in the secondary table because the primary table ID column is a unique identifier.
II need to write a sql query to get the different attachments with same ID like this
Attachment 1 ID – 1234
Attachment 2 ID -1234
Thanks In advance
What I have tried:
I can get one file attached to be viewd since it has no duplicate values in table 1 but doesn't work when attached more than 1 file
推荐答案
Table1
----------
- Table1Key, primary key, auto-generated
- UploadInfo, for example session info about upload
- etc...
既然你想要实际的附件共享一个共同的密钥,那么你会有表1的外键引用。因此,如果表2包含附件,则结构可能类似于
Now since you wanted the actual attachments to share a common key, then you would have a foreign key reference to Table1. So if Table 2 contains the attachments then the structure could be like
Table2
-----------
- Table2Key, primary key, auto-generated
- Table1Key, foreign key, points to Table1
- AttachmentName, file name
- etc
所以数据可能就像
表1
So the data could be like
Table1
Table1Key SessionInfo
--------- ------------
1 Session2, user x
2 Session214, user y
3 Session7, user z
表2
Table2
Table2Key Table1Key AttachmentName
--------- --------- --------------
1 1 FileABC
2 1 FileTRE
3 1 File546
4 2 File495
5 3 FileKLI
6 3 FileSRG
7 3 FileUIU
8 3 FileUIG
9 3 FileCDF
有了这种s结构很容易处理不同数量的附件及其与父表的关系。
With this kind of structure it's easy for you to handle different amounts of attachments and their relations to parent table.
这篇关于tabel1中的相同ID,它是表2中具有相同ID的不同列的PK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!