user2016882
user2016882

Reputation: 1

Cannot insert array elements into database in asp.net. System.String[] is inserted instead

In asp.net I'm inserting array values into a database but array elements are not inserted properly. Instead of that, System.String[] is inserted.

Upvotes: 0

Views: 1351

Answers (2)

scottmetoyer
scottmetoyer

Reputation: 36

System.String[] in the database implies that you are passing the string array directly to your database insert method.

Instead, you'll need to loop through the array and insert the strings as individual rows:

foreach(string s in stringArray)
{
    database.Insert(s);
}

Alternatively, you can flatten the array and insert into a single row like this:

database.Insert(String.Join(",", stringArray))

This would insert the array as a comma-delimited list.

Upvotes: 1

Richard Schneider
Richard Schneider

Reputation: 35477

SQL does not do arrays well. You have mostly likely just done a .ToString() on the array of strings.
Try using string.Join( ", ", mystrings).

As mentioned in the comments, this is not third normal form. Search wikipedia for a good synopsis.

Upvotes: 4

Related Questions