0

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Is it not possible using .Tostring()?
No, ToString() on an array of strings uses Object.ToString() which just returns the class name.
Joining the strings together will work, but it's fragile (what if you have two strings ", " and ", " -- they look like the delimiter). You should structure your database better, so that any one field does not hold multiple values.
I agree. The correct way is to have a table for the array of strings and insert a new row for each string in the array. However, this answers OP's question.
i already have a string seperated with comma stored in database,i m splitting that string as string[] strResult = strObj.Split(','); and now I have to insert the result returned by strResult in database column...
|
1

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.

2 Comments

Seems like you copied my mistake on String.Join
foreach(string s in stringArray) { database.Insert(s); } this is well for insertion but when I m using same loop for updation it doesn't work?Can you tell why so?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.