开发者

C# MySql Storing an arraylist in the database

I have an mysql database in which I开发者_如何学JAVA am storing details of a project. One of these details is the staff associated with the project. In the project table I have a column for staff in the project. In my c# code behind I am storing it in an arraylist. I am wondering is there any way to store that arraylist in a single column in the database?

Thanks


You shouldn't store bunch of entities in a single column.

You'd better create another table and link your first one with second one through relation table.

TableA: id | name
TableB: id | bla
TableRelations: tableA_id | tableB_id

It is called many-to-many relation (N:M as a shorthand)

First random link from google related to many-to-many


Generally storing multiples values in column is an indication of poor database design. It makes it very difficult to efficiently select rows based on criteria within that single column. Having said that, if you really only ever need to select those values on a per row basis then consider using XML

Using XML with MySQL


I think you should certainly follow the concept of many-to-many for this, like pointed by @zerkms. But if you is really interested in saving the ArrayList into a single field, you can serialize this ArrayList to String and store in a VARCHAR field.

About serializing ArrayList to String, you can view some suggested ways in this topic: Dynamically create javascript array with c# code behind.

Remember that you'll need to deserialize when reading back to your application too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜