Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to split string seperated by commas & insert into Sql Database in asp.net c#
Posted

Try this example

C#
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);


   }
   }
 
Share this answer
 
v2
Comments
member60 1-Feb-13 6:14am    
my 5!
Hi ,
Check this
C#
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
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900