Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using Split() Function Insert Value in DataBase?

Author  Topic 

nickjack
Starting Member

34 Posts

Posted - 2008-11-12 : 00:03:15
I have a multiline text box in which admin can enter value.what i need the value in text box will save in database in format like

ID Option
1 Poor
2 Good
3 Average
4 Satisfactory

Note:The Value in Textbox will be in any Format mean it will like

Poor,Good,Average,Satisfactory

or

Poor
Good
Average
Satisfactory

cvraghu
Posting Yak Master

187 Posts

Posted - 2008-11-12 : 00:10:09
The existing design would not allow you to decide the delimiters. There could be multiple ways in which user can enter data. You can design something along this line - have dual list box and make the user choose these options on one and add it to other. You can loop through these chosen options either in UI or backend and add the data to table.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-12 : 00:16:46
for saving this fine in backend, you need to write a user defined function which parses this comma seperated list and saves it as individual value records in table. something like below


http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113563
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-12 : 02:07:43
i have use only '\n' and ',' and ' '
and insert value in Database?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-12 : 02:26:05
quote:
Originally posted by nickjack

i have use only '\n' and ',' and ' '
and insert value in Database?


that will make manipulation complex. try to make delimiter consistent. Otherwise you've write code to identify correct delimiter each time and then split values based on that.
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-12 : 02:45:03
Hi,
Being new to Sql it's hard for me to Understand i am writing again what i need is


I have a Textbox(Multiline) where admin enter value in any format like


poor,poor,poor,poor

or in a format like

poor
poor
poor
poor


what i need is when value is inserted in Database will done in new row? (I have created Db)

ID Options
1 poor
2 poor
3 poor
4 poor

Any Sample Code
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-12 : 03:34:55
i have given you solution for this. But i was just telling it would be better if you can enforce a consistent delimiter (either ',' or '/n') for entered values.
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-12 : 04:53:32
string[] str;
if (TextBox1.Text.IndexOf(",") > 0)
{
str = TextBox1.Text.Split('\n');
}

else
{
str = TextBox1.Text.Split(',');
}

foreach (string s in str)
{
i am writing insert command here

}


But the Problem is Value still save in Single column like [(A,A) or (A A)]
Plz modify it?
Go to Top of Page
   

- Advertisement -