Click here to Skip to main content
11,704,107 members (67,099 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
how to split string seperated by commas & insert into Sql Database in asp.net c#
Posted 25-May-12 20:31pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this example

static void Main()
   {
   string s = "there,is,a,cat";
   //
   // Split string on comma.
   // ... This will separate all the words.
   //
   string[] words = s.Split(',');
   foreach (string word in words)
   {
      //Insert each wrd into database
 //insert(word);

 
   }
   }
  Permalink  
v2
Comments
member60 at 1-Feb-13 6:14am
   
my 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi ,
Check this
string RValue = "1233,frrrr,rrrryy";
         string[] VExist = RValue.Split(',');
         foreach (string item in VExist)
         {
             using (
               SqlConnection con =
                   new SqlConnection(""))
             {
 

                 using (SqlCommand cmd = new SqlCommand("usp_test", con))
                 {
                     cmd.CommandType = CommandType.StoredProcedure;
                     cmd.Parameters.AddWithValue("@tst", VExist[0]);
                     cmd.Parameters.AddWithValue("@tst2", VExist[1]);
                     cmd.Parameters.AddWithValue("@tst2", VExist[2]);
                     cmd.ExecuteNonQuery();
 
                 }
             }
         }

Best Regards
M.Mitwalli
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 520
1 OriginalGriff 500
2 Sergey Alexandrovich Kryukov 381
3 Andy Lanng 294
4 F-ES Sitecore 220
0 OriginalGriff 8,784
1 Sergey Alexandrovich Kryukov 7,843
2 CPallini 5,107
3 Maciej Los 4,726
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 26 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100