Click here to Skip to main content
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 OriginalGriff 467
1 CPallini 400
2 Sergey Alexandrovich Kryukov 348
3 BillWoodruff 254
4 George Jonsson 251
0 OriginalGriff 5,370
1 CPallini 4,360
2 Sergey Alexandrovich Kryukov 3,822
3 George Jonsson 3,037
4 Gihan Liyanage 2,435


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 26 May 2012
Copyright © CodeProject, 1999-2014
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