Boardy
Boardy

Reputation: 36237

Store List<T> array in MySQL Database

I am working on a C# project and I have a List of type DbAndTables e.g.

List<DBAndTableNames> myList = new List<DBAndTableNames>();

I need to store the contents of this list in a MySQL Database but I can't find anything on Google on how to do this oddly. I think I have a slight recollection that I need to convert it to a byte array and then somehow this can be written to the database.

Thanks for any help you can provide.

Update I forgot to mention that this is a multi dimensional list array below is the class definition that the list uses. I've looked at the XMLSerialization but from what I've seen this doesn't support mutli dimensional lists.

public class DatabaseAndTableNames
{
    public string database;
    public List<string> tables = new List<string>();
}

Upvotes: 1

Views: 2572

Answers (2)

Damith
Damith

Reputation: 63105

What you can do is serialize and save it on database. when you need it you can Deserialize it.

Upvotes: 2

djcrabhat
djcrabhat

Reputation: 474

This is kind of a funky way to do it. You should really save it as a one-to-many relationship in a second table. But if you REALLY want to save the contents of an array to a single column in the DB, you'll have to serialize the data to text in some way (XMLSerializer is nice and easy to use) Or if you're just storing a list of strings, create a pipe or command delimited list and save that to the column

Upvotes: 0

Related Questions