Click here to Skip to main content
12,300,021 members (53,935 online)
Rate this:
 
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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 26 May 2012
Copyright © CodeProject, 1999-2016
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